From 100a3d003184e5fbd75732f9ffa5f3684ee0922e Mon Sep 17 00:00:00 2001 From: Tek Hudson Date: Sat, 30 Mar 2024 16:57:45 -0400 Subject: [PATCH] First pass at updating all references from warnings --- custom_components/fpl/fplEntity.py | 12 +++++------- .../fpl/sensor_AverageDailySensor.py | 7 ++++--- .../fpl/sensor_DailyUsageSensor.py | 16 ++++++++-------- custom_components/fpl/sensor_DatesSensor.py | 4 ++-- custom_components/fpl/sensor_KWHSensor.py | 17 ++++++++--------- .../fpl/sensor_ProjectedBillSensor.py | 16 +++++++--------- custom_components/fpl/sensor_test.py | 8 ++++---- 7 files changed, 38 insertions(+), 42 deletions(-) diff --git a/custom_components/fpl/fplEntity.py b/custom_components/fpl/fplEntity.py index 9a6dcc3..8e19df1 100644 --- a/custom_components/fpl/fplEntity.py +++ b/custom_components/fpl/fplEntity.py @@ -2,14 +2,12 @@ from datetime import datetime, timedelta -from homeassistant.components.sensor import SensorEntity, STATE_CLASS_MEASUREMENT +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.const import ( CURRENCY_DOLLAR, - DEVICE_CLASS_ENERGY, - ENERGY_KILO_WATT_HOUR, - DEVICE_CLASS_MONETARY, + UnitOfEnergy, ) from .const import DOMAIN, VERSION, ATTRIBUTION @@ -70,8 +68,8 @@ def getData(self, field): class FplEnergyEntity(FplEntity): """Represents a energy sensor""" - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR - # _attr_device_class = DEVICE_CLASS_ENERGY + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR + # _attr_device_class = SensorDeviceClass.ENERGY _attr_icon = "mdi:flash" @property @@ -87,7 +85,7 @@ class FplMoneyEntity(FplEntity): """Represents a money sensor""" _attr_native_unit_of_measurement = CURRENCY_DOLLAR - _attr_device_class = DEVICE_CLASS_MONETARY + _attr_device_class = SensorDeviceClass.MONETARY _attr_icon = "mdi:currency-usd" diff --git a/custom_components/fpl/sensor_AverageDailySensor.py b/custom_components/fpl/sensor_AverageDailySensor.py index b4298ca..4cffc20 100644 --- a/custom_components/fpl/sensor_AverageDailySensor.py +++ b/custom_components/fpl/sensor_AverageDailySensor.py @@ -1,6 +1,7 @@ """Average daily sensors""" from .fplEntity import FplMoneyEntity +from homeassistant.components.sensor import SensorStateClass class DailyAverageSensor(FplMoneyEntity): """average daily sensor, use budget value if available, otherwise use actual daily values""" @@ -20,7 +21,7 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL + # attributes["state_class"] = SensorStateClass.TOTAL return attributes @@ -42,7 +43,7 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL + # attributes["state_class"] = SensorStateClass.TOTAL return attributes @@ -64,5 +65,5 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL + # attributes["state_class"] = SensorStateClass.TOTAL return attributes diff --git a/custom_components/fpl/sensor_DailyUsageSensor.py b/custom_components/fpl/sensor_DailyUsageSensor.py index f3ae6c8..d1cf187 100644 --- a/custom_components/fpl/sensor_DailyUsageSensor.py +++ b/custom_components/fpl/sensor_DailyUsageSensor.py @@ -1,8 +1,8 @@ """Daily Usage Sensors""" from datetime import timedelta, datetime from homeassistant.components.sensor import ( - STATE_CLASS_TOTAL_INCREASING, - DEVICE_CLASS_ENERGY, + SensorDeviceClass, + SensorStateClass, ) from .fplEntity import FplEnergyEntity, FplMoneyEntity @@ -26,7 +26,7 @@ def customAttributes(self): """Return the state attributes.""" data = self.getData("daily_usage") attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING + # attributes["state_class"] = SensorStateClass.TOTAL_INCREASING if data is not None and len(data) > 0 and "readTime" in data[-1].keys(): attributes["date"] = data[-1]["readTime"] @@ -39,8 +39,8 @@ class FplDailyUsageKWHSensor(FplEnergyEntity): def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Daily Usage KWH") - _attr_state_class = STATE_CLASS_TOTAL_INCREASING - _attr_device_class = DEVICE_CLASS_ENERGY + _attr_state_class = SensorStateClass.TOTAL_INCREASING + _attr_device_class = SensorDeviceClass.ENERGY @property def native_value(self): @@ -69,7 +69,7 @@ def customAttributes(self): # last_reset = date - timedelta(days=1) attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING + # attributes["state_class"] = SensorStateClass.TOTAL_INCREASING # attributes["date"] = date # attributes["last_reset"] = last_reset return attributes @@ -81,7 +81,7 @@ class FplDailyReceivedKWHSensor(FplEnergyEntity): def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Daily Received KWH") - # _attr_state_class = STATE_CLASS_TOTAL_INCREASING + # _attr_state_class = SensorStateClass.TOTAL_INCREASING @property def native_value(self): @@ -108,7 +108,7 @@ def customAttributes(self): class FplDailyDeliveredKWHSensor(FplEnergyEntity): """daily delivered Kwh sensor""" - # _attr_state_class = STATE_CLASS_TOTAL_INCREASING + # _attr_state_class = SensorStateClass.TOTAL_INCREASING def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Daily Delivered KWH") diff --git a/custom_components/fpl/sensor_DatesSensor.py b/custom_components/fpl/sensor_DatesSensor.py index 620fce5..bcaa86f 100644 --- a/custom_components/fpl/sensor_DatesSensor.py +++ b/custom_components/fpl/sensor_DatesSensor.py @@ -1,6 +1,6 @@ """dates sensors""" import datetime -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT +from homeassistant.components.sensor import SensorStateClass from .fplEntity import FplDateEntity, FplDayEntity @@ -42,7 +42,7 @@ class ServiceDaysSensor(FplDayEntity): def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Service Days") - _attr_state_class = STATE_CLASS_MEASUREMENT + _attr_state_class = SensorStateClass.MEASUREMENT @property def native_value(self): diff --git a/custom_components/fpl/sensor_KWHSensor.py b/custom_components/fpl/sensor_KWHSensor.py index ed5ef73..4c4604e 100644 --- a/custom_components/fpl/sensor_KWHSensor.py +++ b/custom_components/fpl/sensor_KWHSensor.py @@ -1,9 +1,8 @@ """energy sensors""" from datetime import date, timedelta from homeassistant.components.sensor import ( - STATE_CLASS_TOTAL_INCREASING, - STATE_CLASS_TOTAL, - DEVICE_CLASS_ENERGY, + SensorDeviceClass, + SensorStateClass, ) from .fplEntity import FplEnergyEntity @@ -26,7 +25,7 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL + # attributes["state_class"] = SensorStateClass.TOTAL return attributes @@ -48,7 +47,7 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL + # attributes["state_class"] = SensorStateClass.TOTAL return attributes @@ -58,8 +57,8 @@ class BillToDateKWHSensor(FplEnergyEntity): def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Bill To Date KWH") - _attr_state_class = STATE_CLASS_TOTAL_INCREASING - _attr_device_class = DEVICE_CLASS_ENERGY + _attr_state_class = SensorStateClass.TOTAL_INCREASING + _attr_device_class = SensorDeviceClass.ENERGY @property def native_value(self): @@ -91,7 +90,7 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING + # attributes["state_class"] = SensorStateClass.TOTAL_INCREASING return attributes @@ -113,5 +112,5 @@ def native_value(self): def customAttributes(self): """Return the state attributes.""" attributes = {} - # attributes["state_class"] = STATE_CLASS_TOTAL_INCREASING + # attributes["state_class"] = SensorStateClass.TOTAL_INCREASING return attributes diff --git a/custom_components/fpl/sensor_ProjectedBillSensor.py b/custom_components/fpl/sensor_ProjectedBillSensor.py index 59b50d4..fe05ec2 100644 --- a/custom_components/fpl/sensor_ProjectedBillSensor.py +++ b/custom_components/fpl/sensor_ProjectedBillSensor.py @@ -1,15 +1,13 @@ """Projected bill sensors""" -from homeassistant.components.sensor import ( - # STATE_CLASS_TOTAL_INCREASING, - STATE_CLASS_TOTAL, -) +# from homeassistant.components.sensor import SensorStateClass.TOTAL + from .fplEntity import FplMoneyEntity class FplProjectedBillSensor(FplMoneyEntity): """Projected bill sensor""" - # _attr_state_class = STATE_CLASS_TOTAL + # _attr_state_class = SensorStateClass.TOTAL def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Projected Bill") @@ -40,7 +38,7 @@ def customAttributes(self): class DeferedAmountSensor(FplMoneyEntity): """Defered amount sensor""" - # _attr_state_class = STATE_CLASS_TOTAL + # _attr_state_class = SensorStateClass.TOTAL def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Defered Amount") @@ -59,7 +57,7 @@ def native_value(self): class ProjectedBudgetBillSensor(FplMoneyEntity): """projected budget bill sensor""" - # _attr_state_class = STATE_CLASS_TOTAL + # _attr_state_class = SensorStateClass.TOTAL def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Projected Budget Bill") @@ -77,7 +75,7 @@ def native_value(self): class ProjectedActualBillSensor(FplMoneyEntity): """projeted actual bill sensor""" - # _attr_state_class = STATE_CLASS_TOTAL + # _attr_state_class = SensorStateClass.TOTAL def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Projected Actual Bill") @@ -95,7 +93,7 @@ def native_value(self): class BillToDateSensor(FplMoneyEntity): """projeted actual bill sensor""" - # _attr_state_class = STATE_CLASS_TOTAL + # _attr_state_class = SensorStateClass.TOTAL def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Bill To Date") diff --git a/custom_components/fpl/sensor_test.py b/custom_components/fpl/sensor_test.py index 69a5892..0d1c49c 100644 --- a/custom_components/fpl/sensor_test.py +++ b/custom_components/fpl/sensor_test.py @@ -1,8 +1,8 @@ """Test Sensors""" from datetime import timedelta, datetime from homeassistant.components.sensor import ( - STATE_CLASS_TOTAL_INCREASING, - DEVICE_CLASS_ENERGY, + SensorDeviceClass, + SensorStateClass, ) from homeassistant.core import callback from homeassistant.const import STATE_UNKNOWN @@ -15,8 +15,8 @@ class TestSensor(FplEnergyEntity): def __init__(self, coordinator, config, account): super().__init__(coordinator, config, account, "Test Sensor") - _attr_state_class = STATE_CLASS_TOTAL_INCREASING - _attr_device_class = DEVICE_CLASS_ENERGY + _attr_state_class = SensorStateClass.TOTAL_INCREASING + _attr_device_class = SensorDeviceClass.ENERGY @property def native_value(self):