Skip to content

Commit

Permalink
Merge pull request #289 from PeteRager/deprecated-constants
Browse files Browse the repository at this point in the history
update deprecated constants
  • Loading branch information
PeteRager authored Jan 14, 2024
2 parents 478c314 + ed6e1d3 commit afc7262
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 77 deletions.
11 changes: 5 additions & 6 deletions custom_components/lennoxs30/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PRESENCE,
DEVICE_CLASS_CONNECTIVITY,
BinarySensorDeviceClass,
BinarySensorEntity,
)

Expand Down Expand Up @@ -181,7 +180,7 @@ def device_info(self) -> DeviceInfo:

@property
def device_class(self):
return DEVICE_CLASS_PRESENCE
return BinarySensorDeviceClass.PRESENCE


class S30InternetStatus(S30BaseEntityMixin, BinarySensorEntity):
Expand Down Expand Up @@ -241,7 +240,7 @@ def device_info(self) -> DeviceInfo:

@property
def device_class(self):
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY

@property
def entity_category(self):
Expand Down Expand Up @@ -304,7 +303,7 @@ def device_info(self) -> DeviceInfo:

@property
def device_class(self):
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY

@property
def entity_category(self):
Expand Down Expand Up @@ -376,7 +375,7 @@ def device_info(self) -> DeviceInfo:

@property
def device_class(self):
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY

@property
def entity_category(self):
Expand Down
7 changes: 3 additions & 4 deletions custom_components/lennoxs30/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
)
from homeassistant.const import (
ATTR_TEMPERATURE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -225,8 +224,8 @@ def supported_features(self):
def temperature_unit(self):
"""Return the unit of measurement."""
if self._manager.is_metric is False:
return TEMP_FAHRENHEIT
return TEMP_CELSIUS
return UnitOfTemperature.FAHRENHEIT
return UnitOfTemperature.CELSIUS

@property
def min_temp(self):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/lennoxs30/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Diagnostics support for Nest."""
"""Diagnostics support for LennoxS30."""
# pylint: disable=line-too-long
from __future__ import annotations
from typing import Any
Expand Down
11 changes: 5 additions & 6 deletions custom_components/lennoxs30/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from homeassistant.components.number import NumberEntity
from homeassistant.const import (
PERCENTAGE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
TIME_MINUTES,
UnitOfTemperature,
UnitOfTime,
)
from homeassistant.helpers import config_validation as cv
from homeassistant.exceptions import HomeAssistantError
Expand Down Expand Up @@ -234,8 +233,8 @@ def name(self):
@property
def native_unit_of_measurement(self):
if self._manager.is_metric is False:
return TEMP_FAHRENHEIT
return TEMP_CELSIUS
return UnitOfTemperature.FAHRENHEIT
return UnitOfTemperature.CELSIUS

@property
def native_max_value(self) -> float:
Expand Down Expand Up @@ -427,7 +426,7 @@ async def async_set_native_value(self, value: float) -> None:

@property
def native_unit_of_measurement(self):
return TIME_MINUTES
return UnitOfTime.MINUTES

@property
def device_info(self) -> DeviceInfo:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_binary_sensor_ble_commstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from unittest.mock import patch

from homeassistant.components.binary_sensor import DEVICE_CLASS_CONNECTIVITY
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from lennoxs30api.s30api_async import lennox_system, LENNOX_BLE_COMMSTATUS_AVAILABLE, LennoxBle
import pytest

Expand Down Expand Up @@ -45,7 +45,7 @@ async def test_binary_sensor_ble_commstatus(hass, manager_system_04_furn_ac_zoni
assert attrs["commStatus"] == "BAD_STATUS"

assert sensor.entity_category == "diagnostic"
assert sensor.device_class == DEVICE_CLASS_CONNECTIVITY
assert sensor.device_class == BinarySensorDeviceClass.CONNECTIVITY

identifiers = sensor.device_info["identifiers"]
for element in identifiers:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_binary_sensor_cloud_connection_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from unittest.mock import patch

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
BinarySensorDeviceClass,
)


Expand All @@ -43,7 +43,7 @@ async def test_cloud_connected_status_init(hass, manager: Manager, caplog):
assert c.available == False

assert c.entity_category == "diagnostic"
assert c.device_class == DEVICE_CLASS_CONNECTIVITY
assert c.device_class == BinarySensorDeviceClass.CONNECTIVITY

identifiers = c.device_info["identifiers"]
for x in identifiers:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_binary_sensor_internet_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from unittest.mock import patch

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
BinarySensorDeviceClass,
)

from tests.conftest import conftest_base_entity_availability
Expand All @@ -31,7 +31,7 @@ async def test_internet_status_init(hass, manager: Manager, caplog):
assert system.internetStatus == None
assert c.available == False
assert c.entity_category == "diagnostic"
assert c.device_class == DEVICE_CLASS_CONNECTIVITY
assert c.device_class == BinarySensorDeviceClass.CONNECTIVITY

identifiers = c.device_info["identifiers"]
for x in identifiers:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_binary_sensor_relay_service_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from unittest.mock import patch

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
BinarySensorDeviceClass,
)

from tests.conftest import conftest_base_entity_availability
Expand All @@ -31,7 +31,7 @@ async def test_relay_service_status_init(hass, manager: Manager, caplog):
assert system.relayServerConnected == None
assert c.available == False
assert c.entity_category == "diagnostic"
assert c.device_class == DEVICE_CLASS_CONNECTIVITY
assert c.device_class == BinarySensorDeviceClass.CONNECTIVITY

identifiers = c.device_info["identifiers"]
for x in identifiers:
Expand Down
7 changes: 3 additions & 4 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
SUPPORT_TARGET_TEMPERATURE_RANGE,
)
from homeassistant.const import (
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature
)


Expand Down Expand Up @@ -94,7 +93,7 @@ async def test_climate_min_max_c(hass, manager_mz: Manager):

# Metric Tests
assert manager.is_metric is True
assert c.temperature_unit == TEMP_CELSIUS
assert c.temperature_unit == UnitOfTemperature.CELSIUS
zone.systemMode = LENNOX_HVAC_OFF
assert c.min_temp is None
assert c.max_temp is None
Expand Down Expand Up @@ -145,7 +144,7 @@ async def test_climate_min_max_f(hass, manager_mz: Manager, caplog):
manager.is_metric = False

assert manager.is_metric is False
assert c.temperature_unit == TEMP_FAHRENHEIT
assert c.temperature_unit == UnitOfTemperature.FAHRENHEIT
zone.systemMode = LENNOX_HVAC_OFF
assert c.min_temp is None
assert c.max_temp is None
Expand Down
8 changes: 4 additions & 4 deletions tests/test_diag_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

from homeassistant.const import (
PERCENTAGE,
TEMP_FAHRENHEIT,
UnitOfTemperature,
FREQUENCY_HERTZ,
ELECTRIC_CURRENT_AMPERE,
VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE,
ELECTRIC_POTENTIAL_VOLT,
TIME_MINUTES,
UnitOfTime,
REVOLUTIONS_PER_MINUTE,
)
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass
Expand Down Expand Up @@ -169,13 +169,13 @@ async def test_diag_sensor_unit_of_measure_device_class(hass, manager: Manager):
equipment = system.equipment[1]
diagnostic = equipment.diagnostics[9]
s = S30DiagSensor(hass, manager, system, equipment, diagnostic)
assert s.native_unit_of_measurement == TEMP_FAHRENHEIT
assert s.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT
assert s.device_class == SensorDeviceClass.TEMPERATURE

equipment = system.equipment[1]
diagnostic = equipment.diagnostics[12]
s = S30DiagSensor(hass, manager, system, equipment, diagnostic)
assert s.unit_of_measurement == TIME_MINUTES
assert s.unit_of_measurement == UnitOfTime.MINUTES
assert s.device_class is None

equipment = system.equipment[1]
Expand Down
43 changes: 23 additions & 20 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from logging import ERROR, WARNING
"""Test for the helper module"""
# pylint: disable=line-too-long
import logging
import pytest
from homeassistant.const import (
PERCENTAGE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
FREQUENCY_HERTZ,
ELECTRIC_CURRENT_AMPERE,
VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE,
ELECTRIC_POTENTIAL_VOLT,
TIME_MINUTES,
TIME_SECONDS,
UnitOfTemperature,
UnitOfFrequency,
UnitOfElectricCurrent,
UnitOfVolumeFlowRate,
UnitOfElectricPotential,
UnitOfTime
)
from custom_components.lennoxs30 import Manager
from custom_components.lennoxs30.const import LENNOX_DOMAIN
Expand All @@ -20,25 +19,26 @@
helper_get_equipment_device_info,
lennox_uom_to_ha_uom,
)
from custom_components.lennoxs30.number import EquipmentParameterNumber


def test_helpers_lennox_uom_to_ha_uom():
assert lennox_uom_to_ha_uom("F") == TEMP_FAHRENHEIT
assert lennox_uom_to_ha_uom("C") == TEMP_CELSIUS
assert lennox_uom_to_ha_uom("CFM") == VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE
assert lennox_uom_to_ha_uom("min") == TIME_MINUTES
assert lennox_uom_to_ha_uom("sec") == TIME_SECONDS
"""Test the conversion of unit from lennox to HA"""
assert lennox_uom_to_ha_uom("F") == UnitOfTemperature.FAHRENHEIT
assert lennox_uom_to_ha_uom("C") == UnitOfTemperature.CELSIUS
assert lennox_uom_to_ha_uom("CFM") == UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE
assert lennox_uom_to_ha_uom("min") == UnitOfTime.MINUTES
assert lennox_uom_to_ha_uom("sec") == UnitOfTime.SECONDS
assert lennox_uom_to_ha_uom("%") == PERCENTAGE
assert lennox_uom_to_ha_uom("Hz") == FREQUENCY_HERTZ
assert lennox_uom_to_ha_uom("V") == ELECTRIC_POTENTIAL_VOLT
assert lennox_uom_to_ha_uom("A") == ELECTRIC_CURRENT_AMPERE
assert lennox_uom_to_ha_uom("") == None
assert lennox_uom_to_ha_uom("Hz") == UnitOfFrequency.HERTZ
assert lennox_uom_to_ha_uom("V") == UnitOfElectricPotential.VOLT
assert lennox_uom_to_ha_uom("A") == UnitOfElectricCurrent.AMPERE
assert lennox_uom_to_ha_uom("") is None
assert lennox_uom_to_ha_uom("my_custom_unit") == "my_custom_unit"


@pytest.mark.asyncio
async def test_helpers_helper_get_equipment_device_info(manager: Manager):
"""Test the helper to create device info"""
await manager.create_devices()
system = manager.api.system_list[0]
device_info = helper_get_equipment_device_info(manager, system, 1)
Expand All @@ -51,6 +51,7 @@ async def test_helpers_helper_get_equipment_device_info(manager: Manager):

@pytest.mark.asyncio
async def test_helpers_helper_get_equipment_device_info_no_system(manager: Manager, caplog):
"""Test the helper to create device info"""
system = manager.api.system_list[0]
with caplog.at_level(logging.ERROR):
caplog.clear()
Expand All @@ -67,6 +68,7 @@ async def test_helpers_helper_get_equipment_device_info_no_system(manager: Manag

@pytest.mark.asyncio
async def test_helpers_helper_get_equipment_device_info_no_device(manager: Manager, caplog):
"""Test the helper to create device info"""
await manager.create_devices()
system = manager.api.system_list[0]
manager.system_equip_device_map[system.sysId] = {}
Expand All @@ -84,7 +86,8 @@ async def test_helpers_helper_get_equipment_device_info_no_device(manager: Manag


@pytest.mark.asyncio
async def test_helpers_create_equipment_entity_name(manager: Manager, caplog):
async def test_helpers_create_equipment_entity_name(manager: Manager):
"""Test the helper to create device info"""
await manager.create_devices()
system = manager.api.system_list[0]
equipment = system.equipment[0]
Expand Down
7 changes: 3 additions & 4 deletions tests/test_number_dehumidification_overcool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import pytest

from homeassistant.const import (
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature
)

from lennoxs30api.s30api_async import (
Expand Down Expand Up @@ -53,9 +52,9 @@ async def test_dehumd_overcool_unique_id_unit_of_measure(hass, manager: Manager)
system: lennox_system = manager.api.system_list[0]
manager.is_metric = True
c = DehumidificationOverCooling(hass, manager, system)
assert c.unit_of_measurement == TEMP_CELSIUS
assert c.unit_of_measurement == UnitOfTemperature.CELSIUS
manager.is_metric = False
assert c.unit_of_measurement == TEMP_FAHRENHEIT
assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT


@pytest.mark.asyncio
Expand Down
4 changes: 2 additions & 2 deletions tests/test_number_equipment_parameter_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from unittest.mock import patch
import pytest

from homeassistant.const import TEMP_FAHRENHEIT
from homeassistant.const import UnitOfTemperature
from homeassistant.exceptions import HomeAssistantError

from lennoxs30api.s30api_async import lennox_system
Expand Down Expand Up @@ -54,7 +54,7 @@ async def test_equipment_parameter_number_unit_of_measure(hass, manager: Manager
equipment = system.equipment[0]
parameter = equipment.parameters[72]
c = EquipmentParameterNumber(hass, manager, system, equipment, parameter)
assert c.unit_of_measurement == TEMP_FAHRENHEIT
assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT


@pytest.mark.asyncio
Expand Down
4 changes: 2 additions & 2 deletions tests/test_number_timed_ventilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unittest.mock import patch
import pytest

from homeassistant.const import TIME_MINUTES
from homeassistant.const import UnitOfTime
from homeassistant.exceptions import HomeAssistantError

from lennoxs30api.s30api_async import lennox_system
Expand Down Expand Up @@ -47,7 +47,7 @@ async def test_timed_ventilation_time_name(hass, manager: Manager):
async def test_timed_ventilation_time_unit_of_measure(hass, manager: Manager):
system: lennox_system = manager.api.system_list[0]
c = TimedVentilationNumber(hass, manager, system)
assert c.unit_of_measurement == TIME_MINUTES
assert c.unit_of_measurement == UnitOfTime.MINUTES


@pytest.mark.asyncio
Expand Down
Loading

0 comments on commit afc7262

Please sign in to comment.