Simply sensor

This commit is contained in:
pssc
2024-07-25 00:11:48 +01:00
parent 71704ae7ea
commit 41b9d7d7b5

View File

@@ -9,12 +9,11 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import SqueezeboxConfigEntry
from .const import STATUS_SENSOR_NEEDSRESTART, STATUS_SENSOR_RESCAN
from .coordinator import LMSStatusDataUpdateCoordinator
from .entity import LMSStatusEntity
SENSORS: tuple[BinarySensorEntityDescription, ...] = (
@@ -47,19 +46,7 @@ async def async_setup_entry(
class ServerStatusBinarySensor(LMSStatusEntity, BinarySensorEntity):
"""LMS Status based sensor from LMS via cooridnatior."""
def __init__(
self,
coordinator: LMSStatusDataUpdateCoordinator,
description: BinarySensorEntityDescription,
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator, description)
# needs to be set as auto update is off
self._attr_is_on = coordinator.data[description.key]
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_is_on = self.coordinator.data[self.entity_description.key]
self.async_write_ha_state()
_LOGGER.debug("Update %s=%s", self.entity_description.key, self._attr_is_on)
@property
def is_on(self) -> bool:
"""LMS Status directly from coordinator data."""
return self.coordinator.data[self.entity_description.key]