Skip to content

Commit

Permalink
Merge pull request #256 from henricm/enums
Browse files Browse the repository at this point in the history
chore: use new enums for energy, power and temperature
  • Loading branch information
argoyle authored Dec 12, 2022
2 parents 0080871 + 586ff2c commit a74a679
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions custom_components/ferroamp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
CONF_NAME,
CONF_PREFIX,
ELECTRIC_CURRENT_AMPERE,
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
FREQUENCY_HERTZ,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
ELECTRIC_POTENTIAL_VOLT
ELECTRIC_POTENTIAL_VOLT,
UnitOfEnergy,
UnitOfPower,
UnitOfTemperature
)
from homeassistant.core import callback
from homeassistant.helpers.entity import DeviceInfo
Expand Down Expand Up @@ -420,7 +419,7 @@ def esm_event_received(msg):
"Rated Capacity",
device_id,
"ratedCapacity",
ENERGY_WATT_HOUR,
UnitOfEnergy.WATT_HOUR,
"mdi:battery",
device_id,
device_name,
Expand Down Expand Up @@ -577,15 +576,15 @@ def __init__(self, name, entity_prefix, unit: str | None, icon, device_id, devic
model=kwargs.get("model")
)
self._attr_should_poll = False
if unit == ENERGY_KILO_WATT_HOUR:
if unit == UnitOfEnergy.KILO_WATT_HOUR:
self._attr_device_class = SensorDeviceClass.ENERGY
elif unit == POWER_WATT:
elif unit == UnitOfPower.WATT:
self._attr_device_class = SensorDeviceClass.POWER
elif unit == ELECTRIC_POTENTIAL_VOLT:
self._attr_device_class = SensorDeviceClass.VOLTAGE
elif unit == ELECTRIC_CURRENT_AMPERE:
self._attr_device_class = SensorDeviceClass.CURRENT
elif unit == TEMP_CELSIUS:
elif unit == UnitOfTemperature.CELSIUS:
self._attr_device_class = SensorDeviceClass.TEMPERATURE
self._interval = interval
entity_id = slugify(name)
Expand Down Expand Up @@ -776,7 +775,7 @@ def handle_options_update(self, options):
class TemperatureFerroampSensor(FloatValFerroampSensor):
def __init__(self, name, entity_prefix, key, device_id, device_name, interval, precision, config_id, **kwargs):
super().__init__(
name, entity_prefix, key, TEMP_CELSIUS, "mdi:thermometer", device_id, device_name, interval, precision, config_id,
name, entity_prefix, key, UnitOfTemperature.CELSIUS, "mdi:thermometer", device_id, device_name, interval, precision, config_id,
**kwargs
)
self._attr_state_class = SensorStateClass.MEASUREMENT
Expand Down Expand Up @@ -838,7 +837,7 @@ def __init__(self, name, entity_prefix, key, icon, device_id, device_name, inter
name,
entity_prefix,
key,
ENERGY_KILO_WATT_HOUR,
UnitOfEnergy.KILO_WATT_HOUR,
icon,
device_id,
device_name,
Expand Down Expand Up @@ -904,7 +903,7 @@ class PowerFerroampSensor(FloatValFerroampSensor):
"""Representation of a Ferroamp Power Sensor."""

def __init__(self, name, entity_prefix, key, icon, device_id, device_name, interval, config_id, **kwargs):
super().__init__(name, entity_prefix, key, POWER_WATT, icon, device_id, device_name, interval, 0, config_id, **kwargs)
super().__init__(name, entity_prefix, key, UnitOfPower.WATT, icon, device_id, device_name, interval, 0, config_id, **kwargs)


class CalculatedPowerFerroampSensor(KeyedFerroampSensor):
Expand All @@ -917,7 +916,7 @@ def __init__(self, name, entity_prefix, voltage_key, current_key, icon, device_i
name,
entity_prefix,
voltage_key,
POWER_WATT,
UnitOfPower.WATT,
icon,
device_id,
device_name,
Expand Down Expand Up @@ -1019,7 +1018,7 @@ def __init__(self, name, entity_prefix, key, icon, device_id, device_name, inter
super().__init__(
name,
entity_prefix, key,
ENERGY_KILO_WATT_HOUR,
UnitOfEnergy.KILO_WATT_HOUR,
icon,
device_id,
device_name,
Expand Down Expand Up @@ -1048,7 +1047,7 @@ def handle_options_update(self, options):
class ThreePhasePowerFerroampSensor(ThreePhaseFerroampSensor):
def __init__(self, name, entity_prefix, key, icon, device_id, device_name, interval, config_id):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, key, POWER_WATT, icon, device_id, device_name, interval, 0, config_id)
super().__init__(name, entity_prefix, key, UnitOfPower.WATT, icon, device_id, device_name, interval, 0, config_id)
self._attr_state_class = SensorStateClass.MEASUREMENT


Expand Down Expand Up @@ -1469,7 +1468,7 @@ def ehub_sensors(slug, interval, precision_battery, precision_current, precision
"Total rated capacity of all batteries",
slug,
"ratedcap",
ENERGY_WATT_HOUR,
UnitOfEnergy.WATT_HOUR,
"mdi:battery",
f"{slug}_{EHUB}",
EHUB_NAME,
Expand Down

0 comments on commit a74a679

Please sign in to comment.