mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Binary sensor platform for integration_blueprint."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from homeassistant.components.binary_sensor import (
|
|
BinarySensorDeviceClass,
|
|
BinarySensorEntity,
|
|
BinarySensorEntityDescription,
|
|
)
|
|
|
|
from .entity import IntegrationBlueprintEntity
|
|
|
|
if TYPE_CHECKING:
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .coordinator import BlueprintDataUpdateCoordinator
|
|
from .data import IntegrationBlueprintConfigEntry
|
|
|
|
ENTITY_DESCRIPTIONS = (
|
|
BinarySensorEntityDescription(
|
|
key="integration_blueprint",
|
|
name="Integration Blueprint Binary Sensor",
|
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
|
),
|
|
)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
|
|
entry: IntegrationBlueprintConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the binary_sensor platform."""
|
|
async_add_entities(
|
|
IntegrationBlueprintBinarySensor(
|
|
coordinator=entry.runtime_data.coordinator,
|
|
entity_description=entity_description,
|
|
)
|
|
for entity_description in ENTITY_DESCRIPTIONS
|
|
)
|
|
|
|
|
|
class IntegrationBlueprintBinarySensor(IntegrationBlueprintEntity, BinarySensorEntity):
|
|
"""integration_blueprint binary_sensor class."""
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: BlueprintDataUpdateCoordinator,
|
|
entity_description: BinarySensorEntityDescription,
|
|
) -> None:
|
|
"""Initialize the binary_sensor class."""
|
|
super().__init__(coordinator)
|
|
self.entity_description = entity_description
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
"""Return true if the binary_sensor is on."""
|
|
return self.coordinator.data.get("title", "") == "foo"
|