diff --git a/custom_components/lennoxs30/binary_sensor.py b/custom_components/lennoxs30/binary_sensor.py index aeb61ae..2dd3dd4 100644 --- a/custom_components/lennoxs30/binary_sensor.py +++ b/custom_components/lennoxs30/binary_sensor.py @@ -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, ) @@ -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): @@ -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): @@ -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): @@ -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): diff --git a/custom_components/lennoxs30/climate.py b/custom_components/lennoxs30/climate.py index 13418e0..1124e77 100644 --- a/custom_components/lennoxs30/climate.py +++ b/custom_components/lennoxs30/climate.py @@ -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 @@ -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): diff --git a/custom_components/lennoxs30/diagnostics.py b/custom_components/lennoxs30/diagnostics.py index 158c84b..f7f709c 100644 --- a/custom_components/lennoxs30/diagnostics.py +++ b/custom_components/lennoxs30/diagnostics.py @@ -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 diff --git a/custom_components/lennoxs30/number.py b/custom_components/lennoxs30/number.py index f0dfe8a..144f7ab 100644 --- a/custom_components/lennoxs30/number.py +++ b/custom_components/lennoxs30/number.py @@ -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 @@ -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: @@ -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: diff --git a/tests/test_binary_sensor_ble_commstatus.py b/tests/test_binary_sensor_ble_commstatus.py index 195ab5b..33cae4e 100644 --- a/tests/test_binary_sensor_ble_commstatus.py +++ b/tests/test_binary_sensor_ble_commstatus.py @@ -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 @@ -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: diff --git a/tests/test_binary_sensor_cloud_connection_status.py b/tests/test_binary_sensor_cloud_connection_status.py index 0a2bbe8..e0a9992 100644 --- a/tests/test_binary_sensor_cloud_connection_status.py +++ b/tests/test_binary_sensor_cloud_connection_status.py @@ -16,7 +16,7 @@ from unittest.mock import patch from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_CONNECTIVITY, + BinarySensorDeviceClass, ) @@ -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: diff --git a/tests/test_binary_sensor_internet_status.py b/tests/test_binary_sensor_internet_status.py index f0ab68f..c819cd0 100644 --- a/tests/test_binary_sensor_internet_status.py +++ b/tests/test_binary_sensor_internet_status.py @@ -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 @@ -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: diff --git a/tests/test_binary_sensor_relay_service_status.py b/tests/test_binary_sensor_relay_service_status.py index 75a69f1..31aeacc 100644 --- a/tests/test_binary_sensor_relay_service_status.py +++ b/tests/test_binary_sensor_relay_service_status.py @@ -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 @@ -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: diff --git a/tests/test_climate.py b/tests/test_climate.py index aa10dbf..afab797 100644 --- a/tests/test_climate.py +++ b/tests/test_climate.py @@ -29,8 +29,7 @@ SUPPORT_TARGET_TEMPERATURE_RANGE, ) from homeassistant.const import ( - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature ) @@ -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 @@ -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 diff --git a/tests/test_diag_sensor.py b/tests/test_diag_sensor.py index 7281be5..e0eb470 100644 --- a/tests/test_diag_sensor.py +++ b/tests/test_diag_sensor.py @@ -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 @@ -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] diff --git a/tests/test_helpers.py b/tests/test_helpers.py index f3789c0..5dfdc89 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -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 @@ -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) @@ -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() @@ -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] = {} @@ -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] diff --git a/tests/test_number_dehumidification_overcool.py b/tests/test_number_dehumidification_overcool.py index da85ae5..1320461 100644 --- a/tests/test_number_dehumidification_overcool.py +++ b/tests/test_number_dehumidification_overcool.py @@ -9,8 +9,7 @@ import pytest from homeassistant.const import ( - TEMP_CELSIUS, - TEMP_FAHRENHEIT, + UnitOfTemperature ) from lennoxs30api.s30api_async import ( @@ -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 diff --git a/tests/test_number_equipment_parameter_number.py b/tests/test_number_equipment_parameter_number.py index b626048..99a903b 100644 --- a/tests/test_number_equipment_parameter_number.py +++ b/tests/test_number_equipment_parameter_number.py @@ -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 @@ -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 diff --git a/tests/test_number_timed_ventilation.py b/tests/test_number_timed_ventilation.py index 3c740bf..30dc150 100644 --- a/tests/test_number_timed_ventilation.py +++ b/tests/test_number_timed_ventilation.py @@ -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 @@ -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 diff --git a/tests/test_outdoor_temperature_sensor.py b/tests/test_outdoor_temperature_sensor.py index ad00cec..2e72aa9 100644 --- a/tests/test_outdoor_temperature_sensor.py +++ b/tests/test_outdoor_temperature_sensor.py @@ -9,8 +9,8 @@ from unittest.mock import patch import pytest -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, DEVICE_CLASS_TEMPERATURE +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass +from homeassistant.const import UnitOfTemperature from lennoxs30api.s30api_async import ( LENNOX_STATUS_GOOD, @@ -41,12 +41,12 @@ async def test_outdoor_temperature_sensor(hass, manager: Manager, caplog): assert len(s.extra_state_attributes) == 0 manager.is_metric = False assert s.native_value == system.outdoorTemperature - assert s.native_unit_of_measurement == TEMP_FAHRENHEIT + assert s.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT manager.is_metric = True assert s.native_value == system.outdoorTemperatureC - assert s.native_unit_of_measurement == TEMP_CELSIUS + assert s.native_unit_of_measurement == UnitOfTemperature.CELSIUS - assert s.device_class == DEVICE_CLASS_TEMPERATURE + assert s.device_class == SensorDeviceClass.TEMPERATURE assert s.state_class == STATE_CLASS_MEASUREMENT identifiers = s.device_info["identifiers"] diff --git a/tests/test_sensor_humidity.py b/tests/test_sensor_humidity.py index 7cf7331..fb466cf 100644 --- a/tests/test_sensor_humidity.py +++ b/tests/test_sensor_humidity.py @@ -9,8 +9,8 @@ from unittest.mock import patch import pytest -from homeassistant.const import PERCENTAGE, DEVICE_CLASS_HUMIDITY -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT +from homeassistant.const import PERCENTAGE +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass from lennoxs30api.s30api_async import ( LENNOX_BAD_STATUS, @@ -42,7 +42,7 @@ async def test_humidity_sensor(hass, manager: Manager, caplog): assert s.state == zone.humidity assert s.unit_of_measurement == PERCENTAGE - assert s.device_class == DEVICE_CLASS_HUMIDITY + assert s.device_class == SensorDeviceClass.HUMIDITY assert s.state_class == STATE_CLASS_MEASUREMENT identifiers = s.device_info["identifiers"] diff --git a/tests/test_sensor_power_inverter.py b/tests/test_sensor_power_inverter.py index db59906..88077ab 100644 --- a/tests/test_sensor_power_inverter.py +++ b/tests/test_sensor_power_inverter.py @@ -17,10 +17,10 @@ S30InverterPowerSensor, ) -from homeassistant.const import TEMP_CELSIUS, POWER_WATT, DEVICE_CLASS_POWER +from homeassistant.const import POWER_WATT from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, + STATE_CLASS_MEASUREMENT, SensorDeviceClass ) @@ -68,7 +68,7 @@ async def test_power_inverter_sensor(hass, manager: Manager, caplog): assert s.unit_of_measurement == POWER_WATT - assert s.device_class == DEVICE_CLASS_POWER + assert s.device_class == SensorDeviceClass.POWER assert s.state_class == STATE_CLASS_MEASUREMENT identifiers = s.device_info["identifiers"] diff --git a/tests/test_sensor_temperature.py b/tests/test_sensor_temperature.py index adc1d91..1e4d3a3 100644 --- a/tests/test_sensor_temperature.py +++ b/tests/test_sensor_temperature.py @@ -9,8 +9,8 @@ from unittest.mock import patch import pytest -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, DEVICE_CLASS_TEMPERATURE -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT +from homeassistant.const import UnitOfTemperature +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass from lennoxs30api.s30api_async import ( LENNOX_BAD_STATUS, @@ -41,12 +41,12 @@ async def test_temperature_sensor(hass, manager: Manager, caplog): manager.is_metric = False assert s.native_value == zone.temperature - assert s.native_unit_of_measurement == TEMP_FAHRENHEIT + assert s.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT manager.is_metric = True assert s.native_value == zone.temperatureC - assert s.native_unit_of_measurement == TEMP_CELSIUS + assert s.native_unit_of_measurement == UnitOfTemperature.CELSIUS - assert s.device_class == DEVICE_CLASS_TEMPERATURE + assert s.device_class == SensorDeviceClass.TEMPERATURE assert s.state_class == STATE_CLASS_MEASUREMENT identifiers = s.device_info["identifiers"]