1 """The read-only binary sensors for APsystems local API integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from APsystemsEZ1
import ReturnAlarmInfo
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
20 from .
import ApSystemsConfigEntry, ApSystemsData
21 from .coordinator
import ApSystemsDataCoordinator
22 from .entity
import ApSystemsEntity
25 @dataclass(frozen=True, kw_only=True)
27 """Describes Apsystens Inverter binary sensor entity."""
29 is_on: Callable[[ReturnAlarmInfo], bool |
None]
32 BINARY_SENSORS: tuple[ApsystemsLocalApiBinarySensorDescription, ...] = (
34 key=
"off_grid_status",
35 translation_key=
"off_grid_status",
36 device_class=BinarySensorDeviceClass.PROBLEM,
37 entity_category=EntityCategory.DIAGNOSTIC,
38 is_on=
lambda c: c.offgrid,
41 key=
"dc_1_short_circuit_error_status",
42 translation_key=
"dc_1_short_circuit_error_status",
43 device_class=BinarySensorDeviceClass.PROBLEM,
44 entity_category=EntityCategory.DIAGNOSTIC,
45 is_on=
lambda c: c.shortcircuit_1,
48 key=
"dc_2_short_circuit_error_status",
49 translation_key=
"dc_2_short_circuit_error_status",
50 device_class=BinarySensorDeviceClass.PROBLEM,
51 entity_category=EntityCategory.DIAGNOSTIC,
52 is_on=
lambda c: c.shortcircuit_2,
55 key=
"output_fault_status",
56 translation_key=
"output_fault_status",
57 device_class=BinarySensorDeviceClass.PROBLEM,
58 entity_category=EntityCategory.DIAGNOSTIC,
59 is_on=
lambda c:
not c.operating,
66 config_entry: ApSystemsConfigEntry,
67 add_entities: AddEntitiesCallback,
69 """Set up the binary sensor platform."""
70 config = config_entry.runtime_data
75 entity_description=desc,
77 for desc
in BINARY_SENSORS
82 CoordinatorEntity[ApSystemsDataCoordinator], ApSystemsEntity, BinarySensorEntity
84 """Base binary sensor to be used with description."""
86 entity_description: ApsystemsLocalApiBinarySensorDescription
91 entity_description: ApsystemsLocalApiBinarySensorDescription,
93 """Initialize the sensor."""
95 ApSystemsEntity.__init__(self, data)
97 self.
_attr_unique_id_attr_unique_id = f
"{data.device_id}_{entity_description.key}"
101 """Return value of sensor."""
None __init__(self, ApSystemsData data, ApsystemsLocalApiBinarySensorDescription entity_description)
None async_setup_entry(HomeAssistant hass, ApSystemsConfigEntry config_entry, AddEntitiesCallback add_entities)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)