mirror of
https://github.com/home-assistant/core.git
synced 2025-08-17 03:21:40 +02:00
Simply sensor
This commit is contained in:
@@ -9,12 +9,11 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import SqueezeboxConfigEntry
|
from . import SqueezeboxConfigEntry
|
||||||
from .const import STATUS_SENSOR_NEEDSRESTART, STATUS_SENSOR_RESCAN
|
from .const import STATUS_SENSOR_NEEDSRESTART, STATUS_SENSOR_RESCAN
|
||||||
from .coordinator import LMSStatusDataUpdateCoordinator
|
|
||||||
from .entity import LMSStatusEntity
|
from .entity import LMSStatusEntity
|
||||||
|
|
||||||
SENSORS: tuple[BinarySensorEntityDescription, ...] = (
|
SENSORS: tuple[BinarySensorEntityDescription, ...] = (
|
||||||
@@ -47,19 +46,7 @@ async def async_setup_entry(
|
|||||||
class ServerStatusBinarySensor(LMSStatusEntity, BinarySensorEntity):
|
class ServerStatusBinarySensor(LMSStatusEntity, BinarySensorEntity):
|
||||||
"""LMS Status based sensor from LMS via cooridnatior."""
|
"""LMS Status based sensor from LMS via cooridnatior."""
|
||||||
|
|
||||||
def __init__(
|
@property
|
||||||
self,
|
def is_on(self) -> bool:
|
||||||
coordinator: LMSStatusDataUpdateCoordinator,
|
"""LMS Status directly from coordinator data."""
|
||||||
description: BinarySensorEntityDescription,
|
return self.coordinator.data[self.entity_description.key]
|
||||||
) -> 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)
|
|
||||||
|
Reference in New Issue
Block a user