1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-01 13:14:35 +01:00
Files
core/homeassistant/components/slack/sensor.py
T
2026-04-30 21:14:48 +02:00

52 lines
1.4 KiB
Python

"""Slack platform for sensor component."""
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