Added component named switcher_kis switcher water heater integration. (#22325)
* Added component named switcher_kis switcher water heater integration. * Fixed conflicts. * Updated requirements. * Added manifest.json file and updated CODEOWNERS. * Fixed requirements_all.txt. * Better component tests. * Removed unnecessary parameter from fixture function. * Removed tests section from mypy.ini. * Remove unused ENTITY_ID_FORMAT. * Stop udp bridge when failed to setup the component. * Replace DISCOVERY_ constants prefix with DATA_. * Various change requests. * Fixed constant name change remifications. * Added explicit name to fixture. * Various change requests. * More various change requests. * Added EventType for homeassistant.core.Event. * Switched from event driven data distribution to dispatcher type plus clean-ups. * Removed name and icon keys from the component configuration. * Various change requests. * Various change reqeusts and clean-ups. * Removed unnecessary DEPENDENCIES constant from swith platform. * Replaced configuration data guard with assert. * Removed unused constants. * Removed confusing type casting for mypy sake. * Refactor property device_name to name. * Removed None guard effecting mypy only. * Removed unnecessary function from switch entity. * Removed None guard in use by mypy only. * Removed unused constant. * Removed unnecessary context manager. * Stopped messing around with mypy.ini. * Referring to typing.TYPE_CHECKING for non-runtime imports. * Added test requierment correctyly. * Replaced queue.get() with queue.get_nowait() to avoid backing up intervals requests. * Revert changes in mypy.ini. * Changed attributes content to device properties instead of entity properties. * Fixed typo in constant name. * Remove unnecessary async keyword from callable. * Waiting for tasks on event loop to end. * Added callback decorator to callable.
This commit is contained in:
1 parent
31e514ec15
commit
9d8d8afa82
13 files changed
+443
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Test cases and object for the Switcher integration tests."""
|
||||
@@ -0,0 +1,110 @@
|
||||
"""Common fixtures and objects for the Switcher integration tests."""
|
||||
|
||||
from asyncio import Queue
|
||||
from datetime import datetime
|
||||
from typing import Any, Generator, Optional
|
||||
|
||||
from asynctest import CoroutineMock, patch
|
||||
from pytest import fixture
|
||||
|
||||
from .consts import (
|
||||
DUMMY_AUTO_OFF_SET, DUMMY_DEVICE_ID, DUMMY_DEVICE_NAME,
|
||||
DUMMY_DEVICE_STATE, DUMMY_ELECTRIC_CURRENT, DUMMY_IP_ADDRESS,
|
||||
DUMMY_MAC_ADDRESS, DUMMY_PHONE_ID, DUMMY_POWER_CONSUMPTION,
|
||||
DUMMY_REMAINING_TIME)
|
||||
|
||||
|
||||
@patch('aioswitcher.devices.SwitcherV2Device')
|
||||
class MockSwitcherV2Device:
|
||||
"""Class for mocking the aioswitcher.devices.SwitcherV2Device object."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the object."""
|
||||
self._last_state_change = datetime.now()
|
||||
|
||||
@property
|
||||
def device_id(self) -> str:
|
||||
"""Return the device id."""
|
||||
return DUMMY_DEVICE_ID
|
||||
|
||||
@property
|
||||
def ip_addr(self) -> str:
|
||||
"""Return the ip address."""
|
||||
return DUMMY_IP_ADDRESS
|
||||
|
||||
@property
|
||||
def mac_addr(self) -> str:
|
||||
"""Return the mac address."""
|
||||
return DUMMY_MAC_ADDRESS
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the device name."""
|
||||
return DUMMY_DEVICE_NAME
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
"""Return the device state."""
|
||||
return DUMMY_DEVICE_STATE
|
||||
|
||||
@property
|
||||
def remaining_time(self) -> Optional[str]:
|
||||
"""Return the time left to auto-off."""
|
||||
return DUMMY_REMAINING_TIME
|
||||
|
||||
@property
|
||||
def auto_off_set(self) -> str:
|
||||
"""Return the auto-off configuration value."""
|
||||
return DUMMY_AUTO_OFF_SET
|
||||
|
||||
@property
|
||||
def power_consumption(self) -> int:
|
||||
"""Return the power consumption in watts."""
|
||||
return DUMMY_POWER_CONSUMPTION
|
||||
|
||||
@property
|
||||
def electric_current(self) -> float:
|
||||
"""Return the power consumption in amps."""
|
||||
return DUMMY_ELECTRIC_CURRENT
|
||||
|
||||
@property
|
||||
def phone_id(self) -> str:
|
||||
"""Return the phone id."""
|
||||
return DUMMY_PHONE_ID
|
||||
|
||||
@property
|
||||
def last_data_update(self) -> datetime:
|
||||
"""Return the timestamp of the last update."""
|
||||
return datetime.now()
|
||||
|
||||
@property
|
||||
def last_state_change(self) -> datetime:
|
||||
"""Return the timestamp of the state change."""
|
||||
return self._last_state_change
|
||||
|
||||
|
||||
@fixture(name='mock_bridge')
|
||||
def mock_bridge_fixture() -> Generator[None, Any, None]:
|
||||
"""Fixture for mocking aioswitcher.bridge.SwitcherV2Bridge."""
|
||||
queue = Queue() # type: Queue
|
||||
|
||||
async def mock_queue():
|
||||
"""Mock asyncio's Queue."""
|
||||
await queue.put(MockSwitcherV2Device())
|
||||
return await queue.get()
|
||||
|
||||
mock_bridge = CoroutineMock()
|
||||
|
||||
patchers = [
|
||||
patch('aioswitcher.bridge.SwitcherV2Bridge.start', new=mock_bridge),
|
||||
patch('aioswitcher.bridge.SwitcherV2Bridge.stop', new=mock_bridge),
|
||||
patch('aioswitcher.bridge.SwitcherV2Bridge.queue', get=mock_queue)
|
||||
]
|
||||
|
||||
for patcher in patchers:
|
||||
patcher.start()
|
||||
|
||||
yield
|
||||
|
||||
for patcher in patchers:
|
||||
patcher.stop()
|
||||
@@ -0,0 +1,26 @@
|
||||
"""Constants for the Switcher integration tests."""
|
||||
|
||||
from homeassistant.components.switcher_kis import (
|
||||
CONF_DEVICE_ID, CONF_DEVICE_PASSWORD, CONF_PHONE_ID, DOMAIN)
|
||||
|
||||
DUMMY_AUTO_OFF_SET = '01:30:00'
|
||||
DUMMY_DEVICE_ID = 'a123bc'
|
||||
DUMMY_DEVICE_NAME = "Device Name"
|
||||
DUMMY_DEVICE_PASSWORD = '12345678'
|
||||
DUMMY_DEVICE_STATE = 'on'
|
||||
DUMMY_ELECTRIC_CURRENT = 12.8
|
||||
DUMMY_ICON = 'mdi:dummy-icon'
|
||||
DUMMY_IP_ADDRESS = '192.168.100.157'
|
||||
DUMMY_MAC_ADDRESS = 'A1:B2:C3:45:67:D8'
|
||||
DUMMY_NAME = 'boiler'
|
||||
DUMMY_PHONE_ID = '1234'
|
||||
DUMMY_POWER_CONSUMPTION = 2780
|
||||
DUMMY_REMAINING_TIME = '01:29:32'
|
||||
|
||||
MANDATORY_CONFIGURATION = {
|
||||
DOMAIN: {
|
||||
CONF_PHONE_ID: DUMMY_PHONE_ID,
|
||||
CONF_DEVICE_ID: DUMMY_DEVICE_ID,
|
||||
CONF_DEVICE_PASSWORD: DUMMY_DEVICE_PASSWORD
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Test cases for the switcher_kis component."""
|
||||
|
||||
from typing import Any, Generator
|
||||
|
||||
from homeassistant.components.switcher_kis import (DOMAIN, DATA_DEVICE)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .consts import (
|
||||
DUMMY_AUTO_OFF_SET, DUMMY_DEVICE_ID, DUMMY_DEVICE_NAME,
|
||||
DUMMY_DEVICE_STATE, DUMMY_ELECTRIC_CURRENT, DUMMY_IP_ADDRESS,
|
||||
DUMMY_MAC_ADDRESS, DUMMY_PHONE_ID, DUMMY_POWER_CONSUMPTION,
|
||||
DUMMY_REMAINING_TIME, MANDATORY_CONFIGURATION)
|
||||
|
||||
|
||||
async def test_failed_config(hass: HomeAssistantType) -> None:
|
||||
"""Test failed configuration."""
|
||||
assert await async_setup_component(
|
||||
hass, DOMAIN, MANDATORY_CONFIGURATION) is False
|
||||
|
||||
|
||||
async def test_minimal_config(hass: HomeAssistantType,
|
||||
mock_bridge: Generator[None, Any, None]
|
||||
) -> None:
|
||||
"""Test setup with configuration minimal entries."""
|
||||
assert await async_setup_component(hass, DOMAIN, MANDATORY_CONFIGURATION)
|
||||
|
||||
|
||||
async def test_discovery_data_bucket(
|
||||
hass: HomeAssistantType,
|
||||
mock_bridge: Generator[None, Any, None]
|
||||
) -> None:
|
||||
"""Test the event send with the updated device."""
|
||||
assert await async_setup_component(
|
||||
hass, DOMAIN, MANDATORY_CONFIGURATION)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = hass.data[DOMAIN].get(DATA_DEVICE)
|
||||
assert device.device_id == DUMMY_DEVICE_ID
|
||||
assert device.ip_addr == DUMMY_IP_ADDRESS
|
||||
assert device.mac_addr == DUMMY_MAC_ADDRESS
|
||||
assert device.name == DUMMY_DEVICE_NAME
|
||||
assert device.state == DUMMY_DEVICE_STATE
|
||||
assert device.remaining_time == DUMMY_REMAINING_TIME
|
||||
assert device.auto_off_set == DUMMY_AUTO_OFF_SET
|
||||
assert device.power_consumption == DUMMY_POWER_CONSUMPTION
|
||||
assert device.electric_current == DUMMY_ELECTRIC_CURRENT
|
||||
assert device.phone_id == DUMMY_PHONE_ID
|
||||
Reference in new issue
Block a user