1 """Support for Ebusd sensors."""
3 from __future__
import annotations
15 from .const
import DOMAIN
17 TIME_FRAME1_BEGIN =
"time_frame1_begin"
18 TIME_FRAME1_END =
"time_frame1_end"
19 TIME_FRAME2_BEGIN =
"time_frame2_begin"
20 TIME_FRAME2_END =
"time_frame2_end"
21 TIME_FRAME3_BEGIN =
"time_frame3_begin"
22 TIME_FRAME3_END =
"time_frame3_end"
23 MIN_TIME_BETWEEN_UPDATES = datetime.timedelta(seconds=15)
25 _LOGGER = logging.getLogger(__name__)
31 add_entities: AddEntitiesCallback,
32 discovery_info: DiscoveryInfoType |
None =
None,
34 """Set up the Ebus sensor."""
35 if not discovery_info:
37 ebusd_api = hass.data[DOMAIN]
38 monitored_conditions = discovery_info[
"monitored_conditions"]
39 name = discovery_info[
"client_name"]
43 EbusdSensor(ebusd_api, discovery_info[
"sensor_types"][condition], name)
44 for condition
in monitored_conditions
51 """Ebusd component sensor methods definition."""
54 """Initialize the sensor."""
59 self._unit_of_measurement,
68 """Return the name of the sensor."""
69 return f
"{self._client_name} {self._name}"
73 """Return the state of the sensor."""
78 """Return the device state attributes."""
81 TIME_FRAME1_BEGIN:
None,
82 TIME_FRAME1_END:
None,
83 TIME_FRAME2_BEGIN:
None,
84 TIME_FRAME2_END:
None,
85 TIME_FRAME3_BEGIN:
None,
86 TIME_FRAME3_END:
None,
88 time_frame = self.
_state_state.split(
";")
89 for index, item
in enumerate(sorted(schedule.items())):
90 if index < len(time_frame):
91 parsed = datetime.datetime.strptime(time_frame[index],
"%H:%M")
92 parsed = parsed.replace(
93 dt_util.now().year, dt_util.now().month, dt_util.now().day
95 schedule[item[0]] = parsed.isoformat()
101 """Return the class of this device, from component DEVICE_CLASSES."""
102 return self._device_class
106 """Icon to use in the frontend, if any."""
111 """Return the unit of measurement."""
112 return self._unit_of_measurement
114 @Throttle(MIN_TIME_BETWEEN_UPDATES)
116 """Fetch new state data for the sensor."""
119 if self._name
not in self.
datadata.value:
122 self.
_state_state = self.
datadata.value[self._name]
124 _LOGGER.debug(
"EbusdData.update exception")
def __init__(self, data, sensor, name)
def native_unit_of_measurement(self)
def extra_state_attributes(self)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
def add_entities(account, async_add_entities, tracked)