1 """Support for OSO Energy binary sensors."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from apyosoenergyapi
import OSOEnergy
7 from apyosoenergyapi.helper.const
import OSOEnergyBinarySensorData
11 BinarySensorEntityDescription,
17 from .const
import DOMAIN
18 from .entity
import OSOEnergyEntity
21 @dataclass(frozen=True, kw_only=True)
23 """Class describing OSO Energy heater binary sensor entities."""
25 value_fn: Callable[[OSOEnergy], bool]
28 SENSOR_TYPES: dict[str, OSOEnergyBinarySensorEntityDescription] = {
31 translation_key=
"power_save",
32 value_fn=
lambda entity_data: entity_data.state,
36 translation_key=
"extra_energy",
37 value_fn=
lambda entity_data: entity_data.state,
41 translation_key=
"heating",
42 value_fn=
lambda entity_data: entity_data.state,
48 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
50 """Set up OSO Energy binary sensor."""
51 osoenergy: OSOEnergy = hass.data[DOMAIN][entry.entry_id]
54 for dev
in osoenergy.session.device_list.get(
"binary_sensor", [])
55 if (sensor_type := SENSOR_TYPES.get(dev.osoEnergyType.lower()))
62 OSOEnergyEntity[OSOEnergyBinarySensorData], BinarySensorEntity
64 """OSO Energy Sensor Entity."""
66 entity_description: OSOEnergyBinarySensorEntityDescription
71 description: OSOEnergyBinarySensorEntityDescription,
72 entity_data: OSOEnergyBinarySensorData,
74 """Set up OSO Energy binary sensor."""
75 super().
__init__(instance, entity_data)
77 device_id = entity_data.device_id
83 """Return the state of the sensor."""
87 """Update all data for OSO Energy."""
88 await self.osoenergy.session.update_data()
89 self.
entity_dataentity_data = await self.osoenergy.binary_sensor.get_sensor(
None __init__(self, OSOEnergy instance, OSOEnergyBinarySensorEntityDescription description, OSOEnergyBinarySensorData entity_data)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)