Skip to content

Commit

Permalink
Update backward tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 18, 2024
1 parent bb8b4ad commit b8bef8c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 59 deletions.
9 changes: 2 additions & 7 deletions custom_components/sonoff/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions custom_components/sonoff/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
8 changes: 6 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
84 changes: 34 additions & 50 deletions tests/test_backward.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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

0 comments on commit b8bef8c

Please sign in to comment.