Skip to content

Commit

Permalink
Remove deprecated units (#197)
Browse files Browse the repository at this point in the history
* Remove deprecated units

* Drop time
  • Loading branch information
elupus authored Jan 1, 2024
1 parent 16f21a7 commit 083163f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
8 changes: 4 additions & 4 deletions climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
CONF_NAME,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
TEMP_CELSIUS,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.event import (
Expand Down Expand Up @@ -204,7 +204,7 @@ def available(self):
@property
def temperature_unit(self):
"""Return temperature unit used."""
return self.get_unit(self._climate.room_temp, TEMP_CELSIUS)
return self.get_unit(self._climate.room_temp, UnitOfTemperature.CELSIUS)

@property
def current_temperature(self):
Expand Down Expand Up @@ -289,7 +289,7 @@ def available(self):
@property
def temperature_unit(self):
"""Return used temperature unit."""
return self.get_unit(self._climate.supply_temp, TEMP_CELSIUS)
return self.get_unit(self._climate.supply_temp, UnitOfTemperature.CELSIUS)

@property
def current_temperature(self):
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(
self._attr_target_temperature_step = 0.5
self._current_temperature_id = current_temperature_id
self._current_temperature: float | None = None
self._attr_temperature_unit = TEMP_CELSIUS
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self._attr_should_poll = False
self._valve_position_id = valve_position_id
self._valve_position: float | None = None
Expand Down
32 changes: 13 additions & 19 deletions sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ELECTRIC_CURRENT_AMPERE,
ELECTRIC_CURRENT_MILLIAMPERE,
ELECTRIC_POTENTIAL_MILLIVOLT,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
ENERGY_MEGA_WATT_HOUR,
ENERGY_WATT_HOUR,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
TEMP_KELVIN,
TIME_HOURS,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfTemperature,
UnitOfTime,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
Expand Down Expand Up @@ -137,15 +131,15 @@ class NibeSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.DURATION,
name="compressor operating time hot water",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=TIME_HOURS,
native_unit_of_measurement=UnitOfTime.HOURS,
icon="mdi:clock",
),
NibeSensorEntityDescription(
key="43420",
device_class=SensorDeviceClass.DURATION,
name="compressor operating time",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=TIME_HOURS,
native_unit_of_measurement=UnitOfTime.HOURS,
icon="mdi:clock",
),
NibeSensorEntityDescription(
Expand Down Expand Up @@ -274,13 +268,13 @@ def device_class(self) -> str | None:
return data

unit = self.native_unit_of_measurement
if unit in {TEMP_CELSIUS, TEMP_FAHRENHEIT, TEMP_KELVIN}:
if unit in UnitOfTemperature._value2member_map_:
return SensorDeviceClass.TEMPERATURE
elif unit in {ELECTRIC_CURRENT_AMPERE, ELECTRIC_CURRENT_MILLIAMPERE}:
elif unit in UnitOfElectricCurrent._value2member_map_:
return SensorDeviceClass.CURRENT
elif unit in {ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_MILLIVOLT}:
elif unit in UnitOfElectricPotential._value2member_map_:
return SensorDeviceClass.VOLTAGE
elif unit in {ENERGY_WATT_HOUR, ENERGY_KILO_WATT_HOUR, ENERGY_MEGA_WATT_HOUR}:
elif unit in UnitOfEnergy._value2member_map_:
return SensorDeviceClass.ENERGY

return None
Expand All @@ -290,7 +284,7 @@ def state_class(self):
"""Return state class of unit."""
if data := super().state_class:
return data
if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR:
if self.native_unit_of_measurement == UnitOfEnergy.KILO_WATT_HOUR:
return SensorStateClass.TOTAL_INCREASING
if self.native_unit_of_measurement:
return SensorStateClass.MEASUREMENT
Expand Down Expand Up @@ -347,7 +341,7 @@ class NibeSystemSensorEntityDescription(SensorEntityDescription):
name="status count",
entity_category=EntityCategory.DIAGNOSTIC,
state_fn=lambda x: len(x.statuses),
attributes_fn = lambda x: {"statuses": x.statuses},
attributes_fn=lambda x: {"statuses": x.statuses},
),
)

Expand Down
4 changes: 2 additions & 2 deletions water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
WaterHeaterEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_OFF, TEMP_CELSIUS
from homeassistant.const import STATE_OFF, UnitOfTemperature
from homeassistant.core import HomeAssistant
from nibeuplink import get_active_hotwater
from nibeuplink.types import HotWaterSystem
Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(self, system: NibeSystem, hwsys: HotWaterSystem):
@property
def temperature_unit(self):
"""Return temperature unit."""
return self.get_unit(self._hwsys.hot_water_charging, TEMP_CELSIUS)
return self.get_unit(self._hwsys.hot_water_charging, UnitOfTemperature.CELSIUS)

@property
def extra_state_attributes(self):
Expand Down

0 comments on commit 083163f

Please sign in to comment.