Skip to content

Commit

Permalink
Update sensor.py to solve deprecated constant
Browse files Browse the repository at this point in the history
To solve log error after updating HA Core 2024.1

Logger: homeassistant.const
Source: helpers/deprecation.py:204

VOLUME_LITERS was used from ecowater_softener, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfVolume.LITERS instead, please create a bug report at https://github.com/barleybobs/homeassistant-ecowater-softener/issues
VOLUME_GALLONS was used from ecowater_softener, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfVolume.GALLONS instead, please create a bug report at https://github.com/barleybobs/homeassistant-ecowater-softener/issues
TIME_DAYS was used from ecowater_softener, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTime.DAYS instead, please create a bug report at https://github.com/barleybobs/homeassistant-ecowater-softener/issues
  • Loading branch information
figorr authored Jan 5, 2024
1 parent d5a8565 commit 2d1af86
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/ecowater_softener/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.const import (
VOLUME_LITERS,
VOLUME_GALLONS,
TIME_DAYS,
UnitOfVolume,
UnitOfTime,
PERCENTAGE,
)

Expand Down Expand Up @@ -80,7 +79,7 @@ class EcowaterSensorEntityDescription(SensorEntityDescription):
key=DAYS_UNTIL_OUT_OF_SALT,
name="Days until out of salt",
icon="mdi:calendar",
native_unit_of_measurement=TIME_DAYS,
native_unit_of_measurement=UnitOfTime.DAYS,
),
EcowaterSensorEntityDescription(
key=RECHARGE_ENABLED,
Expand Down Expand Up @@ -137,9 +136,9 @@ def __init__(
def native_unit_of_measurement(self) -> StateType:
if self.entity_description.key.startswith('water'):
if self.coordinator.data['water_units'].lower() == 'liters':
return VOLUME_LITERS
return UnitOfVolume.LITERS
elif self.coordinator.data['water_units'].lower() == 'gallons':
return VOLUME_GALLONS
return UnitOfVolume.GALLONS
elif self.entity_description.native_unit_of_measurement != None:
return self.entity_description.native_unit_of_measurement

Expand Down

0 comments on commit 2d1af86

Please sign in to comment.