Files
core/homeassistant/components/mutesync/binary_sensor.py
epenet a0e118d411 Migrate mutesync to use runtime_data (#167180)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-02 11:47:51 +02:00

54 lines
1.7 KiB
Python

"""mütesync binary sensor entities."""
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import MutesyncConfigEntry, MutesyncUpdateCoordinator
SENSORS = (
"in_meeting",
"muted",
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: MutesyncConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the mütesync binary sensors."""
coordinator = config_entry.runtime_data
async_add_entities(
[MuteStatus(coordinator, sensor_type) for sensor_type in SENSORS], True
)
class MuteStatus(CoordinatorEntity[MutesyncUpdateCoordinator], BinarySensorEntity):
"""Mütesync binary sensors."""
_attr_has_entity_name = True
def __init__(self, coordinator, sensor_type):
"""Initialize our sensor."""
super().__init__(coordinator)
self._sensor_type = sensor_type
self._attr_translation_key = sensor_type
user_id = coordinator.data["user-id"]
self._attr_unique_id = f"{user_id}-{sensor_type}"
self._attr_device_info = DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN, user_id)},
manufacturer="mütesync",
model="mutesync app",
name="mutesync",
)
@property
def is_on(self) -> bool:
"""Return the state of the sensor."""
return self.coordinator.data[self._sensor_type]