1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-30 20:24:21 +01:00
Files
core/homeassistant/components/peco/binary_sensor.py
2026-04-30 21:14:48 +02:00

52 lines
1.5 KiB
Python

"""Binary sensor for PECO outage counter."""
from typing import Final
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .coordinator import PecoConfigEntry, PecoSmartMeterCoordinator
PARALLEL_UPDATES: Final = 0
async def async_setup_entry(
hass: HomeAssistant,
config_entry: PecoConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up binary sensor for PECO."""
if (coordinator := config_entry.runtime_data.meter_coordinator) is None:
return
async_add_entities(
[PecoBinarySensor(coordinator, phone_number=config_entry.data["phone_number"])]
)
class PecoBinarySensor(
CoordinatorEntity[PecoSmartMeterCoordinator], BinarySensorEntity
):
"""Binary sensor for PECO outage counter."""
_attr_icon = "mdi:gauge"
_attr_device_class = BinarySensorDeviceClass.POWER
_attr_name = "Meter Status"
def __init__(
self, coordinator: PecoSmartMeterCoordinator, phone_number: str
) -> None:
"""Initialize binary sensor for PECO."""
super().__init__(coordinator)
self._attr_unique_id = f"{phone_number}"
@property
def is_on(self) -> bool:
"""Return if the meter has power."""
return self.coordinator.data