Add binary_sensor to Version integration (#66539)
* Add binary_sensor to version integration * Add test to check we not create for local * Move _attr_icon to sensor * Update homeassistant/components/version/binary_sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
af4e37339a
commit
0d2712e436
6 changed files with 130 additions and 29 deletions
61
homeassistant/components/version/binary_sensor.py
Normal file
61
homeassistant/components/version/binary_sensor.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
"""Binary sensor platform for Version."""
|
||||
from __future__ import annotations
|
||||
|
||||
from awesomeversion import AwesomeVersion
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, __version__ as HA_VERSION
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_SOURCE, DEFAULT_NAME, DOMAIN
|
||||
from .coordinator import VersionDataUpdateCoordinator
|
||||
from .entity import VersionEntity
|
||||
|
||||
HA_VERSION_OBJECT = AwesomeVersion(HA_VERSION)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up version binary_sensors."""
|
||||
coordinator: VersionDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
if (source := config_entry.data[CONF_SOURCE]) == "local":
|
||||
return
|
||||
|
||||
if (entity_name := config_entry.data[CONF_NAME]) == DEFAULT_NAME:
|
||||
entity_name = config_entry.title
|
||||
|
||||
entities: list[VersionBinarySensor] = [
|
||||
VersionBinarySensor(
|
||||
coordinator=coordinator,
|
||||
entity_description=BinarySensorEntityDescription(
|
||||
key=str(source),
|
||||
name=f"{entity_name} Update Available",
|
||||
device_class=BinarySensorDeviceClass.UPDATE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class VersionBinarySensor(VersionEntity, BinarySensorEntity):
|
||||
"""Binary sensor for version entities."""
|
||||
|
||||
entity_description: BinarySensorEntityDescription
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the binary sensor is on."""
|
||||
version = self.coordinator.version
|
||||
return version is not None and (version > HA_VERSION_OBJECT)
|
Loading…
Add table
Add a link
Reference in a new issue