Skip to content

Commit

Permalink
Merge pull request #479 from jwillemsen/jwi-202401dep
Browse files Browse the repository at this point in the history
Fixed HA 2024.1.0 deprecation warnings, fixes https://github.com/CJNE…
  • Loading branch information
CJNE authored Feb 18, 2024
2 parents d780ab2 + fd0cbe1 commit 5a8b45e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 57 deletions.
107 changes: 51 additions & 56 deletions custom_components/myenergi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
import operator

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
from homeassistant.const import DEVICE_CLASS_BATTERY
from homeassistant.const import DEVICE_CLASS_ENERGY
from homeassistant.const import DEVICE_CLASS_POWER
from homeassistant.const import DEVICE_CLASS_TEMPERATURE
from homeassistant.const import DEVICE_CLASS_VOLTAGE
from homeassistant.const import ELECTRIC_POTENTIAL_VOLT
from homeassistant.const import ENERGY_KILO_WATT_HOUR
from homeassistant.const import FREQUENCY_HERTZ
from homeassistant.components.sensor import SensorStateClass
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import UnitOfElectricPotential
from homeassistant.const import UnitOfEnergy
from homeassistant.const import UnitOfFrequency
from homeassistant.const import PERCENTAGE
from homeassistant.const import POWER_WATT
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import UnitOfPower
from homeassistant.const import UnitOfTemperature
from homeassistant.helpers.entity import EntityCategory
from pymyenergi import CT_BATTERY
from pymyenergi import CT_LOAD
Expand Down Expand Up @@ -61,11 +56,11 @@ def create_power_meta(name, prop_name, category=None):
return {
"name": name,
"prop_name": prop_name,
"device_class": DEVICE_CLASS_POWER,
"unit": POWER_WATT,
"device_class": SensorDeviceClass.POWER,
"unit": UnitOfPower.WATT,
"category": category,
"icon": "mdi:flash",
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"attrs": {},
}

Expand All @@ -74,11 +69,11 @@ def create_energy_meta(name, prop_name, category=None):
return {
"name": name,
"prop_name": prop_name,
"device_class": DEVICE_CLASS_ENERGY,
"unit": ENERGY_KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"unit": UnitOfEnergy.KILO_WATT_HOUR,
"category": category,
"icon": None,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attrs": {},
}

Expand Down Expand Up @@ -143,11 +138,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Voltage grid",
"voltage_grid",
DEVICE_CLASS_VOLTAGE,
ELECTRIC_POTENTIAL_VOLT,
SensorDeviceClass.VOLTAGE,
UnitOfElectricPotential.VOLT,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_VOLT,
STATE_CLASS_MEASUREMENT,
SensorStateClass.MEASUREMENT,
),
)
)
Expand All @@ -159,10 +154,10 @@ async def async_setup_entry(hass, entry, async_add_devices):
"Frequency grid",
"frequency_grid",
None,
FREQUENCY_HERTZ,
UnitOfFrequency.HERTZ,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_FREQ,
STATE_CLASS_MEASUREMENT,
SensorStateClass.MEASUREMENT,
),
)
)
Expand Down Expand Up @@ -469,8 +464,8 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
f"Temp {device.temp_name_1}",
"temp_1",
DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS,
SensorDeviceClass.TEMPERATURE,
UnitOfTemperature.CELSIUS,
ENTITY_CATEGORY_DIAGNOSTIC,
),
)
Expand All @@ -484,8 +479,8 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
f"Temp {device.temp_name_2}",
"temp_2",
DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS,
SensorDeviceClass.TEMPERATURE,
UnitOfTemperature.CELSIUS,
ENTITY_CATEGORY_DIAGNOSTIC,
),
)
Expand All @@ -499,7 +494,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"SoC",
"state_of_charge",
DEVICE_CLASS_BATTERY,
SensorDeviceClass.BATTERY,
PERCENTAGE,
None,
None,
Expand All @@ -515,11 +510,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Voltage",
"supply_voltage",
DEVICE_CLASS_VOLTAGE,
ELECTRIC_POTENTIAL_VOLT,
SensorDeviceClass.VOLTAGE,
UnitOfElectricPotential.VOLT,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_VOLT,
STATE_CLASS_MEASUREMENT,
SensorStateClass.MEASUREMENT,
),
)
)
Expand All @@ -532,10 +527,10 @@ async def async_setup_entry(hass, entry, async_add_devices):
"Frequency",
"supply_frequency",
None,
FREQUENCY_HERTZ,
UnitOfFrequency.HERTZ,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_FREQ,
STATE_CLASS_MEASUREMENT,
SensorStateClass.MEASUREMENT,
),
)
)
Expand All @@ -548,7 +543,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
"Inverter size",
"inverter_size",
None,
ENERGY_KILO_WATT_HOUR,
UnitOfEnergy.KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_POWER,
),
Expand All @@ -563,7 +558,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
"Battery size",
"battery_size",
None,
ENERGY_KILO_WATT_HOUR,
UnitOfEnergy.KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
ICON_POWER,
),
Expand Down Expand Up @@ -592,11 +587,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Grid import today",
"grid_import",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
SensorDeviceClass.ENERGY,
UnitOfEnergy.KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
SensorStateClass.TOTAL_INCREASING,
),
)
)
Expand All @@ -608,11 +603,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Grid export today",
"grid_export",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
SensorDeviceClass.ENERGY,
UnitOfEnergy.KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
SensorStateClass.TOTAL_INCREASING,
),
)
)
Expand All @@ -624,11 +619,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Battery charge today",
"battery_charge",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
SensorDeviceClass.ENERGY,
UnitOfEnergy.KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
SensorStateClass.TOTAL_INCREASING,
),
)
)
Expand All @@ -640,11 +635,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Battery discharge today",
"battery_discharge",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
SensorDeviceClass.ENERGY,
UnitOfEnergy.KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
SensorStateClass.TOTAL_INCREASING,
),
)
)
Expand All @@ -656,11 +651,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
create_meta(
"Solar generation today",
"generated",
DEVICE_CLASS_ENERGY,
ENERGY_KILO_WATT_HOUR,
SensorDeviceClass.ENERGY,
UnitOfEnergy.KILO_WATT_HOUR,
None,
None,
STATE_CLASS_TOTAL_INCREASING,
SensorStateClass.TOTAL_INCREASING,
),
)
)
Expand Down Expand Up @@ -764,10 +759,10 @@ def __init__(self, coordinator, device, config_entry, key):
meta = {
"name": f"{key.replace('_', ' ')} today",
"prop_name": key,
"device_class": DEVICE_CLASS_ENERGY,
"unit": ENERGY_KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"unit": UnitOfEnergy.KILO_WATT_HOUR,
"category": ENTITY_CATEGORY_DIAGNOSTIC,
"state_class": STATE_CLASS_TOTAL_INCREASING,
"state_class": SensorStateClass.TOTAL_INCREASING,
"icon": None,
"attrs": {},
}
Expand Down Expand Up @@ -819,10 +814,10 @@ def __init__(self, coordinator, device, config_entry, key, category):
meta = {
"name": f"power {key.replace('_', ' ')}",
"prop_name": f"power-{key}",
"device_class": DEVICE_CLASS_POWER,
"state_class": STATE_CLASS_MEASUREMENT,
"device_class": SensorDeviceClass.POWER,
"state_class": SensorStateClass.MEASUREMENT,
"category": category,
"unit": POWER_WATT,
"unit": UnitOfPower.WATT,
"icon": None,
"attrs": {},
}
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "myenergi",
"hacs": "1.6.0",
"render_readme": true,
"homeassistant": "2021.9.1"
"homeassistant": "2024.1.0"
}

0 comments on commit 5a8b45e

Please sign in to comment.