From b8bef8c0037784996c00b76c376e4b361bdb94e9 Mon Sep 17 00:00:00 2001 From: Alex X Date: Thu, 18 Apr 2024 13:48:09 +0300 Subject: [PATCH] Update backward tests --- custom_components/sonoff/config_flow.py | 9 +-- custom_components/sonoff/core/const.py | 1 + tests/__init__.py | 8 ++- tests/test_backward.py | 84 ++++++++++--------------- 4 files changed, 43 insertions(+), 59 deletions(-) diff --git a/custom_components/sonoff/config_flow.py b/custom_components/sonoff/config_flow.py index 86992ec1..b065026d 100644 --- a/custom_components/sonoff/config_flow.py +++ b/custom_components/sonoff/config_flow.py @@ -3,16 +3,11 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow -from homeassistant.const import ( - CONF_COUNTRY_CODE, - CONF_MODE, - CONF_PASSWORD, - CONF_USERNAME, -) +from homeassistant.const import CONF_MODE, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import callback from homeassistant.helpers.aiohttp_client import async_get_clientsession -from .core.const import CONF_DEBUG, CONF_MODES, DOMAIN +from .core.const import CONF_DEBUG, CONF_COUNTRY_CODE, CONF_MODES, DOMAIN from .core.ewelink import XRegistryCloud from .core.ewelink.cloud import REGIONS diff --git a/custom_components/sonoff/core/const.py b/custom_components/sonoff/core/const.py index 96fa047d..3733b8bb 100644 --- a/custom_components/sonoff/core/const.py +++ b/custom_components/sonoff/core/const.py @@ -6,6 +6,7 @@ CONF_DEFAULT_CLASS = "default_class" CONF_DEVICEKEY = "devicekey" CONF_RFBRIDGE = "rfbridge" +CONF_COUNTRY_CODE = "country_code" CONF_MODES = ["auto", "cloud", "local"] diff --git a/tests/__init__.py b/tests/__init__.py index e2dffa26..33942bec 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,7 @@ import asyncio from typing import List -from homeassistant.core import HomeAssistant +from homeassistant.config_entries import HomeAssistant # fix circular import from homeassistant.helpers.entity import Entity from custom_components.sonoff.core.entity import XEntity @@ -46,7 +46,11 @@ def init(device: dict, config: dict = None) -> (XRegistry, List[XEntity]): reg.dispatcher_connect(SIGNAL_ADD_ENTITIES, lambda x: entities.extend(x)) entities += reg.setup_devices(devices) - hass = HomeAssistant("") + try: + hass = HomeAssistant("") # new Hass + except TypeError: + hass = HomeAssistant() # old Hass + for entity in entities: if not isinstance(entity, Entity): continue diff --git a/tests/test_backward.py b/tests/test_backward.py index e8b2e416..5b21bc88 100644 --- a/tests/test_backward.py +++ b/tests/test_backward.py @@ -1,56 +1,40 @@ -from homeassistant.components.button import ButtonEntity -from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode -from homeassistant.components.fan import FanEntityFeature, FanEntity -from homeassistant.components.light import ColorMode, LightEntityFeature -from homeassistant.components.sensor import ( - SensorEntity, - SensorDeviceClass, - SensorStateClass, -) -from homeassistant.const import ( - EntityCategory, - UnitOfElectricCurrent, - UnitOfElectricPotential, - UnitOfEnergy, - UnitOfPower, - UnitOfTemperature, -) -from homeassistant.helpers.entity import Entity - +from homeassistant.const import REQUIRED_PYTHON_VER + +from custom_components.sonoff import * +from custom_components.sonoff.binary_sensor import * +from custom_components.sonoff.button import * +from custom_components.sonoff.climate import * +from custom_components.sonoff.config_flow import * +from custom_components.sonoff.cover import * +from custom_components.sonoff.diagnostics import * +from custom_components.sonoff.fan import * +from custom_components.sonoff.light import * +from custom_components.sonoff.number import * +from custom_components.sonoff.remote import * +from custom_components.sonoff.sensor import * +from custom_components.sonoff.switch import * +from custom_components.sonoff.system_health import * from . import init -def test_2021_9_0(): - sensor = SensorEntity() - assert sensor.native_value is None - assert sensor.native_unit_of_measurement is None - - -def test_2021_12_0(): - assert ButtonEntity - assert EntityCategory - assert FanEntity().percentage is 0 - assert SensorDeviceClass - assert SensorStateClass - - -def test_2022_5_0(): - assert ClimateEntityFeature - assert HVACMode - assert FanEntityFeature - assert ColorMode - assert LightEntityFeature - - -def test_2022_11_0(): - assert UnitOfEnergy - assert UnitOfPower - assert UnitOfTemperature - +def test_backward(): + # https://github.com/home-assistant/core/blob/2023.2.0/homeassistant/const.py + assert REQUIRED_PYTHON_VER >= (3, 10, 0) -def test_2023_1_0(): - assert UnitOfElectricCurrent - assert UnitOfElectricPotential + assert async_setup_entry, async_unload_entry + assert XBinarySensor + assert XRemoteButton + assert XClimateTH + assert SonoffLANFlowHandler + assert XCover + assert async_get_config_entry_diagnostics + assert XFan + assert XOnOffLight + assert XNumber + assert XRemote + assert XSensor + assert XSwitch + assert system_health_info def test_2024_1_cached_properties(): @@ -59,5 +43,5 @@ def test_2024_1_cached_properties(): assert sensor.device_class == SensorDeviceClass.ENERGY _, entities = init({"extra": {"uiid": 1256}}) - sensor: Entity = next(e for e in entities) + sensor: SensorEntity = next(e for e in entities) assert sensor.should_poll is False