Skip to content

Commit

Permalink
fix: remove use of deprecated HA constants (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Jan 9, 2024
1 parent 502cf75 commit b5efbaa
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 81 deletions.
4 changes: 2 additions & 2 deletions custom_components/tesla_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
HVACMode,
)
from homeassistant.components.climate.const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant

from .base import TeslaCarEntity
Expand Down Expand Up @@ -62,7 +62,7 @@ def temperature_unit(self):
Tesla API always returns in Celsius.
"""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def current_temperature(self):
Expand Down
6 changes: 3 additions & 3 deletions custom_components/tesla_custom/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for Tesla device tracker."""
import logging

from homeassistant.components.device_tracker import SOURCE_TYPE_GPS
from homeassistant.components.device_tracker import SourceType
from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.core import HomeAssistant

Expand Down Expand Up @@ -34,7 +34,7 @@ class TeslaCarLocation(TeslaCarEntity, TrackerEntity):
@property
def source_type(self):
"""Return device tracker source type."""
return SOURCE_TYPE_GPS
return SourceType.GPS

@property
def longitude(self):
Expand Down Expand Up @@ -68,7 +68,7 @@ class TeslaCarDestinationLocation(TeslaCarEntity, TrackerEntity):
@property
def source_type(self):
"""Return device tracker source type."""
return SOURCE_TYPE_GPS
return SourceType.GPS

@property
def longitude(self):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tesla_custom/number.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Support for Tesla numbers."""
from homeassistant.components.number import NumberEntity, NumberMode
from homeassistant.const import ELECTRIC_CURRENT_AMPERE, PERCENTAGE
from homeassistant.const import PERCENTAGE, UnitOfElectricCurrent
from homeassistant.core import HomeAssistant
from homeassistant.helpers.icon import icon_for_battery_level
from teslajsonpy.const import (
Expand Down Expand Up @@ -108,7 +108,7 @@ def native_max_value(self) -> int:
@property
def native_unit_of_measurement(self) -> str:
"""Return percentage."""
return ELECTRIC_CURRENT_AMPERE
return UnitOfElectricCurrent.AMPERE


class TeslaEnergyBackupReserve(TeslaEnergyEntity, NumberEntity):
Expand Down
42 changes: 19 additions & 23 deletions custom_components/tesla_custom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
SensorStateClass,
)
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
LENGTH_KILOMETERS,
LENGTH_MILES,
PERCENTAGE,
POWER_KILO_WATT,
POWER_WATT,
PRESSURE_BAR,
PRESSURE_PSI,
SPEED_MILES_PER_HOUR,
TEMP_CELSIUS,
UnitOfEnergy,
UnitOfLength,
UnitOfPower,
UnitOfPressure,
UnitOfSpeed,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -148,7 +144,7 @@ class TeslaCarChargerEnergy(TeslaCarEntity, SensorEntity):
type = "energy added"
_attr_device_class = SensorDeviceClass.ENERGY
_attr_state_class = SensorStateClass.TOTAL_INCREASING
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
_attr_icon = "mdi:lightning-bolt"

@property
Expand All @@ -173,7 +169,7 @@ def extra_state_attributes(self):

if self._car.gui_distance_units == DISTANCE_UNITS_KM_HR:
added_range = DistanceConverter.convert(
added_range, LENGTH_MILES, LENGTH_KILOMETERS
added_range, UnitOfLength.MILES, UnitOfLength.KILOMETERS
)

return {
Expand All @@ -187,7 +183,7 @@ class TeslaCarChargerPower(TeslaCarEntity, SensorEntity):
type = "charger power"
_attr_device_class = SensorDeviceClass.POWER
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = POWER_KILO_WATT
_attr_native_unit_of_measurement = UnitOfPower.KILO_WATT

@property
def native_value(self) -> int:
Expand All @@ -212,7 +208,7 @@ class TeslaCarChargerRate(TeslaCarEntity, SensorEntity):
type = "charging rate"
_attr_device_class = SensorDeviceClass.SPEED
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = SPEED_MILES_PER_HOUR
_attr_native_unit_of_measurement = UnitOfSpeed.MILES_PER_HOUR
_attr_icon = "mdi:speedometer"

@property
Expand All @@ -239,7 +235,7 @@ class TeslaCarOdometer(TeslaCarEntity, SensorEntity):
type = "odometer"
_attr_device_class = SensorDeviceClass.DISTANCE
_attr_state_class = SensorStateClass.TOTAL_INCREASING
_attr_native_unit_of_measurement = LENGTH_MILES
_attr_native_unit_of_measurement = UnitOfLength.MILES
_attr_icon = "mdi:counter"

@property
Expand Down Expand Up @@ -293,7 +289,7 @@ class TeslaCarRange(TeslaCarEntity, SensorEntity):
type = "range"
_attr_device_class = SensorDeviceClass.DISTANCE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = LENGTH_MILES
_attr_native_unit_of_measurement = UnitOfLength.MILES
_attr_icon = "mdi:gauge"

@property
Expand All @@ -319,7 +315,7 @@ def extra_state_attributes(self):
)
if est_battery_range is not None:
est_battery_range_km = DistanceConverter.convert(
est_battery_range, LENGTH_MILES, LENGTH_KILOMETERS
est_battery_range, UnitOfLength.MILES, UnitOfLength.KILOMETERS
)
else:
est_battery_range_km = None
Expand All @@ -336,7 +332,7 @@ class TeslaCarTemp(TeslaCarEntity, SensorEntity):
type = "temperature"
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_icon = "mdi:thermometer"

def __init__(
Expand Down Expand Up @@ -367,7 +363,7 @@ class TeslaEnergyPowerSensor(TeslaEnergyEntity, SensorEntity):

_attr_device_class = SensorDeviceClass.POWER
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = POWER_WATT
_attr_native_unit_of_measurement = UnitOfPower.WATT

def __init__(
self,
Expand Down Expand Up @@ -435,7 +431,7 @@ class TeslaEnergyBatteryRemaining(TeslaEnergyEntity, SensorEntity):
type = "battery remaining"
_attr_device_class = SensorDeviceClass.ENERGY_STORAGE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = ENERGY_WATT_HOUR
_attr_native_unit_of_measurement = UnitOfEnergy.WATT_HOUR

@property
def native_value(self) -> int:
Expand Down Expand Up @@ -526,8 +522,8 @@ class TeslaCarTpmsPressureSensor(TeslaCarEntity, SensorEntity):

_attr_device_class = SensorDeviceClass.PRESSURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = PRESSURE_BAR
_attr_suggested_unit_of_measurement = PRESSURE_PSI
_attr_native_unit_of_measurement = UnitOfPressure.BAR
_attr_suggested_unit_of_measurement = UnitOfPressure.PSI
_attr_icon = "mdi:gauge-full"

def __init__(
Expand Down Expand Up @@ -619,7 +615,7 @@ class TeslaCarDistanceToArrival(TeslaCarEntity, SensorEntity):
type = "distance to arrival"
_attr_device_class = SensorDeviceClass.DISTANCE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = LENGTH_MILES
_attr_native_unit_of_measurement = UnitOfLength.MILES
_attr_icon = "mdi:map-marker-distance"

@property
Expand Down
Loading

0 comments on commit b5efbaa

Please sign in to comment.