2021-03-01 08:41:04 +00:00
|
|
|
"""Binary sensor platform for Hass.io addons."""
|
2021-03-18 08:25:40 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-03-01 08:41:04 +00:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-04-29 10:28:14 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-03-01 08:41:04 +00:00
|
|
|
|
|
|
|
from . import ADDONS_COORDINATOR
|
|
|
|
from .const import ATTR_UPDATE_AVAILABLE
|
|
|
|
from .entity import HassioAddonEntity, HassioOSEntity
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
2021-04-29 10:28:14 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2021-03-01 08:41:04 +00:00
|
|
|
) -> None:
|
|
|
|
"""Binary sensor set up for Hass.io config entry."""
|
|
|
|
coordinator = hass.data[ADDONS_COORDINATOR]
|
|
|
|
|
|
|
|
entities = [
|
|
|
|
HassioAddonBinarySensor(
|
|
|
|
coordinator, addon, ATTR_UPDATE_AVAILABLE, "Update Available"
|
|
|
|
)
|
2021-03-03 13:37:36 +00:00
|
|
|
for addon in coordinator.data["addons"].values()
|
2021-03-01 08:41:04 +00:00
|
|
|
]
|
|
|
|
if coordinator.is_hass_os:
|
|
|
|
entities.append(
|
|
|
|
HassioOSBinarySensor(coordinator, ATTR_UPDATE_AVAILABLE, "Update Available")
|
|
|
|
)
|
|
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
|
|
|
|
class HassioAddonBinarySensor(HassioAddonEntity, BinarySensorEntity):
|
|
|
|
"""Binary sensor to track whether an update is available for a Hass.io add-on."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if the binary sensor is on."""
|
|
|
|
return self.addon_info[self.attribute_name]
|
|
|
|
|
|
|
|
|
|
|
|
class HassioOSBinarySensor(HassioOSEntity, BinarySensorEntity):
|
|
|
|
"""Binary sensor to track whether an update is available for Hass.io OS."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if the binary sensor is on."""
|
|
|
|
return self.os_info[self.attribute_name]
|