1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
# Copyright Tomer Figenblat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Switcher integration devices dataclasses test cases."""
from dataclasses import dataclass
from assertpy import assert_that
from pytest import fixture, mark
from aioswitcher.device import (
DeviceState,
DeviceType,
ShutterDirection,
SwitcherPowerPlug,
SwitcherShutter,
SwitcherThermostat,
SwitcherWaterHeater,
ThermostatFanLevel,
ThermostatMode,
ThermostatSwing,
)
@dataclass(frozen=True)
class FakeData:
"""Fake data for unit tests."""
device_id: str = "aaaaaa"
device_key: str = "18"
ip_address: str = "192.168.1.33"
mac_address: str = "12:A1:A2:1A:BC:1A"
name: str = "My Switcher Boiler"
token_needed: bool = False
power_consumption: int = 2600
electric_current: float = 11.8
remaining_time: str = "01:30:00"
auto_shutdown: str = "03:00:00"
mode: ThermostatMode = ThermostatMode.COOL
fan_level: ThermostatFanLevel = ThermostatFanLevel.HIGH
swing: ThermostatSwing = ThermostatSwing.OFF
target_temperature: int = 24
temperature: float = 26.5
remote_id: str = "ELEC7022"
position: int = 50
direction: ShutterDirection = ShutterDirection.SHUTTER_STOP
@fixture
def fake_data():
return FakeData()
@mark.parametrize("device_type", [DeviceType.MINI, DeviceType.TOUCH, DeviceType.V2_ESP, DeviceType.V2_QCA, DeviceType.V4])
def test_given_a_device_of_type_water_heater_when_instantiating_as_a_water_heater_should_be_instatiated_properly(fake_data, device_type):
sut = SwitcherWaterHeater(
device_type,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.power_consumption,
fake_data.electric_current,
fake_data.remaining_time,
fake_data.auto_shutdown,
)
assert_that(sut.device_type).is_equal_to(device_type)
assert_that(sut.device_state).is_equal_to(DeviceState.ON)
assert_that(sut.device_id).is_equal_to(fake_data.device_id)
assert_that(sut.ip_address).is_equal_to(fake_data.ip_address)
assert_that(sut.mac_address).is_equal_to(fake_data.mac_address)
assert_that(sut.name).is_equal_to(fake_data.name)
assert_that(sut.power_consumption).is_equal_to(fake_data.power_consumption)
assert_that(sut.electric_current).is_equal_to(fake_data.electric_current)
assert_that(sut.remaining_time).is_equal_to(fake_data.remaining_time)
assert_that(sut.auto_shutdown).is_equal_to(fake_data.auto_shutdown)
assert_that(sut.auto_off_set).is_equal_to(fake_data.auto_shutdown)
def test_given_a_device_of_type_power_plug_when_instantiating_as_a_power_plug_should_be_instatiated_properly(fake_data):
sut = SwitcherPowerPlug(
DeviceType.POWER_PLUG,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.power_consumption,
fake_data.electric_current,
)
assert_that(sut.device_type).is_equal_to(DeviceType.POWER_PLUG)
assert_that(sut.device_state).is_equal_to(DeviceState.ON)
assert_that(sut.device_id).is_equal_to(fake_data.device_id)
assert_that(sut.ip_address).is_equal_to(fake_data.ip_address)
assert_that(sut.mac_address).is_equal_to(fake_data.mac_address)
assert_that(sut.name).is_equal_to(fake_data.name)
assert_that(sut.power_consumption).is_equal_to(fake_data.power_consumption)
assert_that(sut.electric_current).is_equal_to(fake_data.electric_current)
def test_given_a_device_of_type_thermostat_when_instantiating_as_a_thermostat_should_be_instatiated_properly(fake_data):
sut = SwitcherThermostat(
DeviceType.BREEZE,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.mode,
fake_data.temperature,
fake_data.target_temperature,
fake_data.fan_level,
fake_data.swing,
fake_data.remote_id
)
assert_that(sut.device_type).is_equal_to(DeviceType.BREEZE)
assert_that(sut.device_state).is_equal_to(DeviceState.ON)
assert_that(sut.device_id).is_equal_to(fake_data.device_id)
assert_that(sut.ip_address).is_equal_to(fake_data.ip_address)
assert_that(sut.mac_address).is_equal_to(fake_data.mac_address)
assert_that(sut.name).is_equal_to(fake_data.name)
assert_that(sut.mode).is_equal_to(fake_data.mode)
assert_that(sut.temperature).is_equal_to(fake_data.temperature)
assert_that(sut.target_temperature).is_equal_to(fake_data.target_temperature)
assert_that(sut.fan_level).is_equal_to(fake_data.fan_level)
assert_that(sut.swing).is_equal_to(fake_data.swing)
assert_that(sut.remote_id).is_equal_to(fake_data.remote_id)
def test_given_a_device_of_type_shutter_when_instantiating_as_a_shutter_should_be_instatiated_properly(fake_data):
sut = SwitcherShutter(
DeviceType.RUNNER,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.position,
fake_data.direction
)
assert_that(sut.device_type).is_equal_to(DeviceType.RUNNER)
assert_that(sut.device_state).is_equal_to(DeviceState.ON)
assert_that(sut.device_id).is_equal_to(fake_data.device_id)
assert_that(sut.ip_address).is_equal_to(fake_data.ip_address)
assert_that(sut.mac_address).is_equal_to(fake_data.mac_address)
assert_that(sut.name).is_equal_to(fake_data.name)
assert_that(sut.position).is_equal_to(fake_data.position)
assert_that(sut.direction).is_equal_to(fake_data.direction)
@mark.parametrize("device_type", [DeviceType.MINI, DeviceType.TOUCH, DeviceType.V2_ESP, DeviceType.V2_QCA, DeviceType.V4])
def test_given_a_device_of_type_water_heater_when_instantiating_as_a_power_plug_should_raise_an_error(fake_data, device_type):
assert_that(SwitcherPowerPlug).raises(ValueError).when_called_with(
device_type,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.power_consumption,
fake_data.electric_current,
).is_equal_to("only power plugs are allowed")
def test_given_a_device_of_type_power_plug_when_instantiating_as_a_water_heater_should_raise_an_error(fake_data):
assert_that(SwitcherWaterHeater).raises(ValueError).when_called_with(
DeviceType.POWER_PLUG,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.power_consumption,
fake_data.electric_current,
fake_data.remaining_time,
fake_data.auto_shutdown,
).is_equal_to("only water heaters are allowed")
def test_given_a_device_of_type_power_plug_when_instantiating_as_a_thermostatr_should_raise_an_error(fake_data):
assert_that(SwitcherThermostat).raises(ValueError).when_called_with(
DeviceType.POWER_PLUG,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.mode,
fake_data.temperature,
fake_data.target_temperature,
fake_data.fan_level,
fake_data.swing,
fake_data.remote_id
).is_equal_to("only thermostats are allowed")
def test_given_a_device_of_type_power_plug_when_instantiating_as_a_shutter_should_raise_an_error(fake_data):
assert_that(SwitcherShutter).raises(ValueError).when_called_with(
DeviceType.POWER_PLUG,
DeviceState.ON,
fake_data.device_id,
fake_data.device_key,
fake_data.ip_address,
fake_data.mac_address,
fake_data.name,
fake_data.token_needed,
fake_data.position,
fake_data.direction
).is_equal_to("only shutters are allowed")
|