-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
/
Copy pathbinary_sensor.py
54 lines (38 loc) · 1.52 KB
/
binary_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Binary sensor platform for IronOS integration."""
from __future__ import annotations
from enum import StrEnum
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import IronOSConfigEntry
from .coordinator import IronOSLiveDataCoordinator
from .entity import IronOSBaseEntity
# Coordinator is used to centralize the data updates
PARALLEL_UPDATES = 0
class PinecilBinarySensor(StrEnum):
"""Pinecil Binary Sensors."""
TIP_CONNECTED = "tip_connected"
async def async_setup_entry(
hass: HomeAssistant,
entry: IronOSConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up binary sensors from a config entry."""
coordinator = entry.runtime_data.live_data
entity_description = BinarySensorEntityDescription(
key=PinecilBinarySensor.TIP_CONNECTED,
translation_key=PinecilBinarySensor.TIP_CONNECTED,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
)
async_add_entities([IronOSBinarySensorEntity(coordinator, entity_description)])
class IronOSBinarySensorEntity(IronOSBaseEntity, BinarySensorEntity):
"""Representation of a IronOS binary sensor entity."""
coordinator: IronOSLiveDataCoordinator
@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
return self.coordinator.has_tip