mirror of
https://github.com/home-assistant/core.git
synced 2026-05-04 20:04:35 +02:00
a54ea071f8
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
"""Slack platform for sensor component."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from slack_sdk.web.async_client import AsyncWebClient
|
|
|
|
from homeassistant.components.sensor import (
|
|
SensorDeviceClass,
|
|
SensorEntity,
|
|
SensorEntityDescription,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
from homeassistant.util import dt as dt_util
|
|
|
|
from . import SlackConfigEntry
|
|
from .const import ATTR_SNOOZE
|
|
from .entity import SlackEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: SlackConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the Slack sensor."""
|
|
async_add_entities(
|
|
[
|
|
SlackSensorEntity(
|
|
entry.runtime_data,
|
|
SensorEntityDescription(
|
|
key="do_not_disturb_until",
|
|
translation_key="do_not_disturb_until",
|
|
device_class=SensorDeviceClass.TIMESTAMP,
|
|
),
|
|
entry,
|
|
)
|
|
],
|
|
True,
|
|
)
|
|
|
|
|
|
class SlackSensorEntity(SlackEntity, SensorEntity):
|
|
"""Representation of a Slack sensor."""
|
|
|
|
_client: AsyncWebClient
|
|
|
|
async def async_update(self) -> None:
|
|
"""Get the latest status."""
|
|
if _time := (await self._client.dnd_info()).get(ATTR_SNOOZE):
|
|
self._attr_native_value = dt_util.utc_from_timestamp(_time)
|
|
else:
|
|
self._attr_native_value = None
|