1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add sensor tests for devolo_home_control (#74292)

This commit is contained in:
Guido Schmitz
2022-12-08 19:40:45 +01:00
committed by GitHub
parent 54fb4df3aa
commit 500b00bd66
4 changed files with 235 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ from devolo_home_control_api.properties.binary_sensor_property import (
from devolo_home_control_api.properties.binary_switch_property import (
BinarySwitchProperty,
)
from devolo_home_control_api.properties.consumption_property import ConsumptionProperty
from devolo_home_control_api.properties.multi_level_sensor_property import (
MultiLevelSensorProperty,
)
@@ -43,6 +44,19 @@ class BinarySwitchPropertyMock(BinarySwitchProperty):
self.element_uid = "Test"
class ConsumptionPropertyMock(ConsumptionProperty):
"""devolo Home Control binary sensor mock."""
def __init__(self, **kwargs: Any) -> None:
"""Initialize the mock."""
self._logger = MagicMock()
self.element_uid = "devolo.Meter:Test"
self.current_unit = "W"
self.total_unit = "kWh"
self._current = 0.0
self._total = 0.0
class MultiLevelSensorPropertyMock(MultiLevelSensorProperty):
"""devolo Home Control multi level sensor mock."""
@@ -135,6 +149,19 @@ class ClimateMock(DeviceMock):
self.multi_level_sensor_property = {"Test": MultiLevelSensorPropertyMock()}
class ConsumptionMock(DeviceMock):
"""devolo Home Control meter device mock."""
def __init__(self) -> None:
"""Initialize the mock."""
super().__init__()
self.consumption_property = {"devolo.Meter:Test": ConsumptionPropertyMock()}
self.multi_level_sensor_property = {
"devolo.VoltageMultiLevelSensor:Test": MultiLevelSensorPropertyMock()
}
class CoverMock(DeviceMock):
"""devolo Home Control cover device mock."""
@@ -195,6 +222,17 @@ class SirenMock(DeviceMock):
self.settings_property["tone"] = SettingsMock()
class SensorMock(DeviceMock):
"""devolo Home Control sensor device mock."""
def __init__(self) -> None:
"""Initialize the mock."""
super().__init__()
self.multi_level_sensor_property = {
"devolo.MultiLevelSensor:Test": MultiLevelSensorPropertyMock()
}
class HomeControlMock(HomeControl):
"""devolo Home Control gateway mock."""
@@ -203,7 +241,7 @@ class HomeControlMock(HomeControl):
self.devices = {}
self.publisher = MagicMock()
def websocket_disconnect(self, event: str):
def websocket_disconnect(self, event: str = "") -> None:
"""Mock disconnect of the websocket."""
@@ -234,6 +272,19 @@ class HomeControlMockClimate(HomeControlMock):
self.publisher.unregister = MagicMock()
class HomeControlMockConsumption(HomeControlMock):
"""devolo Home Control gateway mock with meter devices."""
def __init__(self, **kwargs: Any) -> None:
"""Initialize the mock."""
super().__init__()
self.devices = {
"Test": ConsumptionMock(),
}
self.publisher = Publisher(self.devices.keys())
self.publisher.unregister = MagicMock()
class HomeControlMockCover(HomeControlMock):
"""devolo Home Control gateway mock with cover devices."""
@@ -280,6 +331,19 @@ class HomeControlMockDisabledBinarySensor(HomeControlMock):
self.devices = {"Test": DisabledBinarySensorMock()}
class HomeControlMockSensor(HomeControlMock):
"""devolo Home Control gateway mock with sensor devices."""
def __init__(self, **kwargs: Any) -> None:
"""Initialize the mock."""
super().__init__()
self.devices = {
"Test": SensorMock(),
}
self.publisher = Publisher(self.devices.keys())
self.publisher.unregister = MagicMock()
class HomeControlMockSiren(HomeControlMock):
"""devolo Home Control gateway mock with siren device."""