Skip to content

Commit

Permalink
Remove deprecated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bentekkie committed Dec 31, 2024
1 parent 008dbb5 commit 0e59fdd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
8 changes: 1 addition & 7 deletions custom_components/generac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion custom_components/generac/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 36 additions & 31 deletions custom_components/generac/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -64,7 +63,7 @@ def sensors(item: Item) -> list[Type[GeneracEntity]]:
class StatusSensor(GeneracEntity, SensorEntity):
"""generac Sensor class."""

options = [
_attr_options = [
"Ready",
"Running",
"Exercising",
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions custom_components/generac/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0e59fdd

Please sign in to comment.