Skip to content

Commit

Permalink
Use EntityDescription for binary sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Feb 11, 2023
1 parent 9daa431 commit d5b9b11
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions custom_components/integration_blueprint/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
"""Binary sensor platform for integration_blueprint."""
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorEntityDescription,
BinarySensorDeviceClass,
)

from .const import BINARY_SENSOR, BINARY_SENSOR_DEVICE_CLASS, DEFAULT_NAME, DOMAIN
from .coordinator import BlueprintDataUpdateCoordinator

from .const import DOMAIN
from .entity import IntegrationBlueprintEntity


ENTITY_DESCRIPTIONS = (
BinarySensorEntityDescription(
key="integration_blueprint",
name="Integration Blueprint Sensor",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
),
)


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup binary_sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([IntegrationBlueprintBinarySensor(coordinator, entry)])
async_add_devices(
IntegrationBlueprintBinarySensor(
coordinator=coordinator,
entity_description=entity_description,
)
for entity_description in ENTITY_DESCRIPTIONS
)


class IntegrationBlueprintBinarySensor(IntegrationBlueprintEntity, BinarySensorEntity):
"""integration_blueprint binary_sensor class."""

@property
def name(self):
"""Return the name of the binary_sensor."""
return f"{DEFAULT_NAME}_{BINARY_SENSOR}"

@property
def device_class(self):
"""Return the class of this binary_sensor."""
return BINARY_SENSOR_DEVICE_CLASS
def __init__(
self,
coordinator: BlueprintDataUpdateCoordinator,
entity_description: BinarySensorEntityDescription,
) -> None:
super().__init__(coordinator)
self.entity_description = entity_description

@property
def is_on(self):
Expand Down

0 comments on commit d5b9b11

Please sign in to comment.