Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Slack platform for sensor component."""
2 
3 from __future__ import annotations
4 
5 from slack import WebClient
6 
8  SensorDeviceClass,
9  SensorEntity,
10  SensorEntityDescription,
11 )
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 import homeassistant.util.dt as dt_util
16 
17 from .const import ATTR_SNOOZE, DOMAIN, SLACK_DATA
18 from .entity import SlackEntity
19 
20 
22  hass: HomeAssistant,
23  entry: ConfigEntry,
24  async_add_entities: AddEntitiesCallback,
25 ) -> None:
26  """Set up the Slack select."""
28  [
30  hass.data[DOMAIN][entry.entry_id][SLACK_DATA],
32  key="do_not_disturb_until",
33  translation_key="do_not_disturb_until",
34  device_class=SensorDeviceClass.TIMESTAMP,
35  ),
36  entry,
37  )
38  ],
39  True,
40  )
41 
42 
44  """Representation of a Slack sensor."""
45 
46  _client: WebClient
47 
48  async def async_update(self) -> None:
49  """Get the latest status."""
50  if _time := (await self._client_client.dnd_info()).get(ATTR_SNOOZE):
51  self._attr_native_value_attr_native_value = dt_util.utc_from_timestamp(_time)
52  else:
53  self._attr_native_value_attr_native_value = None
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:25