Skip to content

Commit

Permalink
Replace deprectated constants for HA 2024.05
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Empringham authored and Tim Empringham committed May 2, 2024
1 parent db9f03d commit 6a88925
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
41 changes: 20 additions & 21 deletions custom_components/omnilogic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
STATE_CLASS_MEASUREMENT,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
ELECTRIC_POTENTIAL_MILLIVOLT,
MASS_GRAMS,
UnitOfElectricPotential,
UnitOfMass,
PERCENTAGE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
VOLUME_LITERS,
UnitOfTemperature,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -117,12 +116,12 @@ def native_value(self):
sensor_data = self.coordinator.data[self._item_id][self._state_key]

hayward_state = sensor_data
hayward_unit_of_measure = TEMP_FAHRENHEIT
hayward_unit_of_measure = UnitOfTemperature.FAHRENHEIT
state = sensor_data

if self._unit_type == "Metric":
hayward_state = round((int(hayward_state) - 32) * 5 / 9, 1)
hayward_unit_of_measure = TEMP_CELSIUS
hayward_unit_of_measure = UnitOfTemperature.CELSIUS

if int(sensor_data) == -1 or int(sensor_data) == 255:
hayward_state = None
Expand All @@ -131,7 +130,7 @@ def native_value(self):
self._attrs["hayward_temperature"] = hayward_state
self._attrs["hayward_unit_of_measure"] = hayward_unit_of_measure

self._unit = TEMP_FAHRENHEIT
self._unit = UnitOfTemperature.FAHRENHEIT

return state

Expand Down Expand Up @@ -183,7 +182,7 @@ def native_value(self):

if self._unit_type == "Metric":
salt_return = round(int(salt_return) / 1000, 2)
unit_of_measurement = f"{MASS_GRAMS}/{VOLUME_LITERS}"
unit_of_measurement = f"{UnitOfMass.GRAMS}/{UnitOfVolume.LITERS}"

self._unit = unit_of_measurement

Expand Down Expand Up @@ -269,10 +268,10 @@ def native_value(self):
"name": "Air Temperature",
"kind": "air_temperature",
"device_class": SensorDeviceClass.TEMPERATURE,
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": None,
"unit": TEMP_FAHRENHEIT,
"native_unit_of_measurement": TEMP_FAHRENHEIT,
"unit": UnitOfTemperature.FAHRENHEIT,
"native_unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
"guard_condition": [{}],
},
],
Expand All @@ -282,10 +281,10 @@ def native_value(self):
"name": "Water Temperature",
"kind": "water_temperature",
"device_class": SensorDeviceClass.TEMPERATURE,
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": None,
"unit": TEMP_FAHRENHEIT,
"native_unit_of_measurement": TEMP_FAHRENHEIT,
"unit": UnitOfTemperature.FAHRENHEIT,
"native_unit_of_measurement": UnitOfTemperature.FAHRENHEIT,
"guard_condition": [{}],
},
],
Expand Down Expand Up @@ -341,7 +340,7 @@ def native_value(self):
"name": "Average Salt Level",
"kind": "average_salt_level",
"device_class": None,
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:gauge",
"unit": CONCENTRATION_PARTS_PER_MILLION,
"guard_condition": [
Expand All @@ -356,7 +355,7 @@ def native_value(self):
"name": "Instant Salt Level",
"kind": "instant_salt_level",
"device_class": None,
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:gauge",
"unit": CONCENTRATION_PARTS_PER_MILLION,
"guard_condition": [
Expand All @@ -373,7 +372,7 @@ def native_value(self):
"name": "pH",
"kind": "csad_ph",
"device_class": None,
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:gauge",
"unit": "pH",
"guard_condition": [
Expand All @@ -385,9 +384,9 @@ def native_value(self):
"name": "ORP",
"kind": "csad_orp",
"device_class": None,
"state_class": STATE_CLASS_MEASUREMENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:gauge",
"unit": ELECTRIC_POTENTIAL_MILLIVOLT,
"unit": UnitOfElectricPotential.MILLIVOLT,
"guard_condition": [
{"orp": ""},
],
Expand Down
5 changes: 2 additions & 3 deletions custom_components/omnilogic/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from homeassistant.components.water_heater import (
STATE_OFF,
STATE_ON,
SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE,
WaterHeaterEntityFeature,
WaterHeaterEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand All @@ -17,7 +16,7 @@
from .common import OmniLogicEntity, OmniLogicUpdateCoordinator, check_guard
from .const import COORDINATOR, DOMAIN

SUPPORT_FLAGS_HEATER = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
SUPPORT_FLAGS_HEATER = WaterHeaterEntityFeature.TARGET_TEMPERATURE | WaterHeaterEntityFeature.OPERATION_MODE
OPERATION_LIST = [STATE_ON, STATE_OFF]


Expand Down

0 comments on commit 6a88925

Please sign in to comment.