From 0e59fdd2c08825105c424b6ea492379a8e363704 Mon Sep 17 00:00:00 2001 From: Ben Segall Date: Tue, 31 Dec 2024 13:52:59 -0500 Subject: [PATCH] Remove deprecated stuff --- custom_components/generac/__init__.py | 8 +--- custom_components/generac/entity.py | 2 +- custom_components/generac/sensor.py | 67 ++++++++++++++------------- custom_components/generac/weather.py | 9 ++-- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/custom_components/generac/__init__.py b/custom_components/generac/__init__.py index fe0b336..3a6f74a 100644 --- a/custom_components/generac/__init__.py +++ b/custom_components/generac/__init__.py @@ -46,13 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data[DOMAIN][entry.entry_id] = coordinator - for platform in PLATFORMS: - if entry.options.get(platform, True): - coordinator.platforms.append(platform) - hass.async_add_job( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) - + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) entry.add_update_listener(async_reload_entry) return True diff --git a/custom_components/generac/entity.py b/custom_components/generac/entity.py index 6fe5db6..357458d 100644 --- a/custom_components/generac/entity.py +++ b/custom_components/generac/entity.py @@ -3,7 +3,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import callback -from homeassistant.helpers.entity import DeviceInfo +from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ATTRIBUTION diff --git a/custom_components/generac/sensor.py b/custom_components/generac/sensor.py index 7587b0d..9251f68 100644 --- a/custom_components/generac/sensor.py +++ b/custom_components/generac/sensor.py @@ -2,11 +2,10 @@ from datetime import datetime from typing import Type -from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor.const import SensorDeviceClass from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS -from homeassistant.const import TEMP_FAHRENHEIT +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -64,7 +63,7 @@ def sensors(item: Item) -> list[Type[GeneracEntity]]: class StatusSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - options = [ + _attr_options = [ "Ready", "Running", "Exercising", @@ -73,8 +72,8 @@ class StatusSensor(GeneracEntity, SensorEntity): "Communication Issue", "Unknown", ] - icon = "mdi:power" - device_class = SensorDeviceClass.ENUM + _attr_icon = "mdi:power" + _attr_device_class = SensorDeviceClass.ENUM @property def name(self): @@ -84,24 +83,27 @@ def name(self): @property def native_value(self): """Return the state of the sensor.""" + options = self.options + if options is None: + return None if self.aparatus_detail.apparatusStatus is None: - return self.options[-1] + return options[-1] index = self.aparatus_detail.apparatusStatus - 1 - if index < 0 or index > len(self.options) - 1: - index = len(self.options) - 1 - return self.options[index] + if index < 0 or index > len(options) - 1: + index = len(options) - 1 + return options[index] class DeviceTypeSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - options = [ + _attr_options = [ "Wifi", "Ethernet", "MobileData", "Unknown", ] - device_class = SensorDeviceClass.ENUM + _attr_device_class = SensorDeviceClass.ENUM @property def name(self): @@ -111,24 +113,27 @@ def name(self): @property def native_value(self): """Return the state of the sensor.""" + options = self.options + if options is None: + return None if self.aparatus_detail.deviceType is None: - return self.options[-1] + return options[-1] if self.aparatus_detail.deviceType == "wifi": - return self.options[0] + return options[0] if self.aparatus_detail.deviceType == "eth": - return self.options[1] + return options[1] if self.aparatus_detail.deviceType == "lte": - return self.options[2] + return options[2] if self.aparatus_detail.deviceType == "cdma": - return self.options[2] - return self.options[-1] + return options[2] + return options[-1] class RunTimeSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.DURATION - native_unit_of_measurement = "h" + _attr_device_class = SensorDeviceClass.DURATION + _attr_native_unit_of_measurement = "h" @property def name(self): @@ -152,8 +157,8 @@ def native_value(self): class ProtectionTimeSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.DURATION - native_unit_of_measurement = "h" + _attr_device_class = SensorDeviceClass.DURATION + _attr_native_unit_of_measurement = "h" @property def name(self): @@ -177,7 +182,7 @@ def native_value(self): class ActivationDateSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.TIMESTAMP + _attr_device_class = SensorDeviceClass.TIMESTAMP @property def name(self): @@ -197,7 +202,7 @@ def native_value(self): class LastSeenSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.TIMESTAMP + _attr_device_class = SensorDeviceClass.TIMESTAMP @property def name(self): @@ -217,7 +222,7 @@ def native_value(self): class ConnectionTimeSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.TIMESTAMP + _attr_device_class = SensorDeviceClass.TIMESTAMP @property def name(self): @@ -237,8 +242,8 @@ def native_value(self): class BatteryVoltageSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.VOLTAGE - native_unit_of_measurement = "V" + _attr_device_class = SensorDeviceClass.VOLTAGE + _attr_native_unit_of_measurement = "V" @property def name(self): @@ -262,7 +267,7 @@ def native_value(self): class OutdoorTemperatureSensor(GeneracEntity, SensorEntity): """generac Sensor class.""" - device_class = SensorDeviceClass.TEMPERATURE + _attr_device_class = SensorDeviceClass.TEMPERATURE @property def name(self): @@ -276,10 +281,10 @@ def native_unit_of_measurement(self): or self.aparatus_detail.weather.temperature is None or self.aparatus_detail.weather.temperature.unit is None ): - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS if "f" in self.aparatus_detail.weather.temperature.unit.lower(): - return TEMP_FAHRENHEIT - return TEMP_CELSIUS + return UnitOfTemperature.FAHRENHEIT + return UnitOfTemperature.CELSIUS @property def native_value(self): diff --git a/custom_components/generac/weather.py b/custom_components/generac/weather.py index 94ab3f7..49dd220 100644 --- a/custom_components/generac/weather.py +++ b/custom_components/generac/weather.py @@ -3,8 +3,7 @@ from homeassistant.components.weather import WeatherEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TEMP_CELSIUS -from homeassistant.const import TEMP_FAHRENHEIT +from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -163,10 +162,10 @@ def native_temperature_unit(self): or self.aparatus_detail.weather.temperature is None or self.aparatus_detail.weather.temperature.unit is None ): - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS if "f" in self.aparatus_detail.weather.temperature.unit.lower(): - return TEMP_FAHRENHEIT - return TEMP_CELSIUS + return UnitOfTemperature.FAHRENHEIT + return UnitOfTemperature.CELSIUS @property def native_temperature(self):