2019-06-06 20:55:08 +00:00
|
|
|
"""Support for Streamlabs Water Monitor Away Mode."""
|
2022-01-03 12:13:03 +00:00
|
|
|
from __future__ import annotations
|
2019-06-06 20:55:08 +00:00
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
2023-12-26 21:24:28 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-03 12:13:03 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-06-06 20:55:08 +00:00
|
|
|
|
2023-12-26 21:24:28 +00:00
|
|
|
from . import StreamlabsCoordinator
|
|
|
|
from .const import DOMAIN
|
2024-01-04 20:52:38 +00:00
|
|
|
from .entity import StreamlabsWaterEntity
|
2019-06-06 20:55:08 +00:00
|
|
|
|
|
|
|
|
2023-12-26 21:24:28 +00:00
|
|
|
async def async_setup_entry(
|
2022-01-03 12:13:03 +00:00
|
|
|
hass: HomeAssistant,
|
2023-12-26 21:24:28 +00:00
|
|
|
entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-03 12:13:03 +00:00
|
|
|
) -> None:
|
2023-12-26 21:24:28 +00:00
|
|
|
"""Set up Streamlabs water binary sensor from a config entry."""
|
|
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
2019-06-06 20:55:08 +00:00
|
|
|
|
2024-01-04 20:52:38 +00:00
|
|
|
async_add_entities(
|
|
|
|
StreamlabsAwayMode(coordinator, location_id) for location_id in coordinator.data
|
|
|
|
)
|
2019-06-06 20:55:08 +00:00
|
|
|
|
|
|
|
|
2024-01-04 20:52:38 +00:00
|
|
|
class StreamlabsAwayMode(StreamlabsWaterEntity, BinarySensorEntity):
|
2019-06-06 20:55:08 +00:00
|
|
|
"""Monitor the away mode state."""
|
|
|
|
|
2024-01-04 20:52:38 +00:00
|
|
|
_attr_translation_key = "away_mode"
|
|
|
|
|
2023-12-26 21:24:28 +00:00
|
|
|
def __init__(self, coordinator: StreamlabsCoordinator, location_id: str) -> None:
|
2019-06-06 20:55:08 +00:00
|
|
|
"""Initialize the away mode device."""
|
2024-01-04 20:52:38 +00:00
|
|
|
super().__init__(coordinator, location_id, "away_mode")
|
2019-06-06 20:55:08 +00:00
|
|
|
|
|
|
|
@property
|
2023-12-26 21:24:28 +00:00
|
|
|
def is_on(self) -> bool:
|
2019-06-06 20:55:08 +00:00
|
|
|
"""Return if away mode is on."""
|
2023-12-26 21:24:28 +00:00
|
|
|
return self.location_data.is_away
|