Remove deprecated update binary sensor from Supervisor (#78664)

This commit is contained in:
Joakim Sørensen 2022-09-18 09:58:14 +02:00 committed by GitHub
parent 1f7c90baa0
commit 69c5d910d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 54 deletions

View File

@ -13,14 +13,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ADDONS_COORDINATOR from . import ADDONS_COORDINATOR
from .const import ( from .const import ATTR_STARTED, ATTR_STATE, DATA_KEY_ADDONS
ATTR_STARTED, from .entity import HassioAddonEntity
ATTR_STATE,
ATTR_UPDATE_AVAILABLE,
DATA_KEY_ADDONS,
DATA_KEY_OS,
)
from .entity import HassioAddonEntity, HassioOSEntity
@dataclass @dataclass
@ -30,17 +24,7 @@ class HassioBinarySensorEntityDescription(BinarySensorEntityDescription):
target: str | None = None target: str | None = None
COMMON_ENTITY_DESCRIPTIONS = ( ADDON_ENTITY_DESCRIPTIONS = (
HassioBinarySensorEntityDescription(
# Deprecated, scheduled to be removed in 2022.6
device_class=BinarySensorDeviceClass.UPDATE,
entity_registry_enabled_default=False,
key=ATTR_UPDATE_AVAILABLE,
name="Update available",
),
)
ADDON_ENTITY_DESCRIPTIONS = COMMON_ENTITY_DESCRIPTIONS + (
HassioBinarySensorEntityDescription( HassioBinarySensorEntityDescription(
device_class=BinarySensorDeviceClass.RUNNING, device_class=BinarySensorDeviceClass.RUNNING,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
@ -59,28 +43,15 @@ async def async_setup_entry(
"""Binary sensor set up for Hass.io config entry.""" """Binary sensor set up for Hass.io config entry."""
coordinator = hass.data[ADDONS_COORDINATOR] coordinator = hass.data[ADDONS_COORDINATOR]
entities: list[HassioAddonBinarySensor | HassioOSBinarySensor] = [] async_add_entities(
HassioAddonBinarySensor(
for entity_description in ADDON_ENTITY_DESCRIPTIONS: addon=addon,
for addon in coordinator.data[DATA_KEY_ADDONS].values(): coordinator=coordinator,
entities.append( entity_description=entity_description,
HassioAddonBinarySensor( )
addon=addon, for addon in coordinator.data[DATA_KEY_ADDONS].values()
coordinator=coordinator, for entity_description in ADDON_ENTITY_DESCRIPTIONS
entity_description=entity_description, )
)
)
if coordinator.is_hass_os:
for entity_description in COMMON_ENTITY_DESCRIPTIONS:
entities.append(
HassioOSBinarySensor(
coordinator=coordinator,
entity_description=entity_description,
)
)
async_add_entities(entities)
class HassioAddonBinarySensor(HassioAddonEntity, BinarySensorEntity): class HassioAddonBinarySensor(HassioAddonEntity, BinarySensorEntity):
@ -97,12 +68,3 @@ class HassioAddonBinarySensor(HassioAddonEntity, BinarySensorEntity):
if self.entity_description.target is None: if self.entity_description.target is None:
return value return value
return value == self.entity_description.target return value == self.entity_description.target
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.coordinator.data[DATA_KEY_OS][self.entity_description.key]

View File

@ -42,7 +42,6 @@ EVENT_SUPERVISOR_EVENT = "supervisor_event"
ATTR_AUTO_UPDATE = "auto_update" ATTR_AUTO_UPDATE = "auto_update"
ATTR_VERSION = "version" ATTR_VERSION = "version"
ATTR_VERSION_LATEST = "version_latest" ATTR_VERSION_LATEST = "version_latest"
ATTR_UPDATE_AVAILABLE = "update_available"
ATTR_CPU_PERCENT = "cpu_percent" ATTR_CPU_PERCENT = "cpu_percent"
ATTR_CHANGELOG = "changelog" ATTR_CHANGELOG = "changelog"
ATTR_MEMORY_PERCENT = "memory_percent" ATTR_MEMORY_PERCENT = "memory_percent"

View File

@ -137,9 +137,6 @@ def mock_all(aioclient_mock, request):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"entity_id,expected", "entity_id,expected",
[ [
("binary_sensor.home_assistant_operating_system_update_available", "off"),
("binary_sensor.test_update_available", "on"),
("binary_sensor.test2_update_available", "off"),
("binary_sensor.test_running", "on"), ("binary_sensor.test_running", "on"),
("binary_sensor.test2_running", "off"), ("binary_sensor.test2_running", "off"),
], ],