async def test_update_failure(self): aqualink = asynctest.MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} r = AqualinkSystem.from_data(aqualink, data) r.aqualink.send_home_screen_request = async_raises await r.update() assert r.last_run_success is False assert r.online is None
async def get_systems(self) -> Dict[str, "AqualinkSystems"]: r = await self._send_systems_request() if r.status == 200: data = await r.json() systems = [AqualinkSystem.from_data(self, x) for x in data] return {x.serial: x for x in systems if x is not None} raise Exception( f"Unable to retrieve systems list: {r.status} {r.reason}")
async def test_update_offline(self): aqualink = asynctest.MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} r = AqualinkSystem.from_data(aqualink, data) r.aqualink.send_home_screen_request = async_noop r.aqualink.send_devices_screen_request = async_noop r._parse_home_response = async_raises(AqualinkSystemOfflineException) await r.update() assert r.last_run_success is True assert r.online is False
async def test_update_service_exception(self): aqualink = asynctest.MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} r = AqualinkSystem.from_data(aqualink, data) r.aqualink.send_home_screen_request = async_raises( AqualinkServiceException ) with pytest.raises(AqualinkServiceException): await r.update() assert r.online is None
async def test_update_success(self): aqualink = MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} r = AqualinkSystem.from_data(aqualink, data) r.aqualink.send_home_screen_request = async_noop r.aqualink.send_devices_screen_request = async_noop r._parse_home_response = async_noop r._parse_devices_response = async_noop await r.update() assert r.online is True
async def get_systems(self) -> Dict[str, AqualinkSystem]: try: r = await self._send_systems_request() except AqualinkServiceException as e: if "404" in str(e): raise AqualinkServiceUnauthorizedException from e raise data = await r.json() systems = [AqualinkSystem.from_data(self, x) for x in data] return {x.serial: x for x in systems if x is not None}
async def test_parse_devices_offline(self): data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} aqualink = asynctest.MagicMock() system = AqualinkSystem.from_data(aqualink, data) message = {"message": "", "devices_screen": [{"status": "Offline"}]} response = asynctest.MagicMock() response.json = asynctest.CoroutineMock(return_value=message) with pytest.raises(AqualinkSystemOfflineException): await system._parse_devices_response(response) assert system.devices == {}
def setUp(self) -> None: super().setUp() data = { "id": 123456, "serial_number": "SN123456", "created_at": "2017-09-23T01:00:08.000Z", "updated_at": "2017-09-23T01:00:08.000Z", "name": "Pool", "device_type": "iaqua", "owner_id": None, "updating": False, "firmware_version": None, "target_firmware_version": None, "update_firmware_start_at": None, "last_activity_at": None, } self.sut = AqualinkSystem.from_data(self.client, data=data) self.sut_class = IaquaSystem
async def test_parse_devices_good(self): data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} aqualink = asynctest.MagicMock() system = AqualinkSystem.from_data(aqualink, data) message = { "message": "", "devices_screen": [ {"status": "Online"}, {"response": ""}, {"group": "1"}, { "aux_B1": [ {"state": "0"}, {"label": "Label B1"}, {"icon": "aux_1_0.png"}, {"type": "0"}, {"subtype": "0"}, ] }, ], } response = asynctest.MagicMock() response.json = asynctest.CoroutineMock(return_value=message) expected = { "aux_B1": AqualinkAuxToggle( system=system, data={ "aux": "B1", "name": "aux_B1", "state": "0", "label": "Label B1", "icon": "aux_1_0.png", "type": "0", "subtype": "0", }, ) } await system._parse_devices_response(response) assert system.devices == expected
def test_from_data_unsupported(self) -> None: aqualink = MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "foo"} with pytest.raises(AqualinkSystemUnsupportedException): AqualinkSystem.from_data(aqualink, data)
def test_from_data_iaqua(self) -> None: aqualink = MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} r = AqualinkSystem.from_data(aqualink, data) assert r is not None
def test_from_data_unsupported(self): aqualink = asynctest.MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "foo"} r = AqualinkSystem.from_data(aqualink, data) assert r is None
def test_from_data_iaqua(self): aqualink = asynctest.MagicMock() data = {"id": 1, "serial_number": "ABCDEFG", "device_type": "iaqua"} r = AqualinkSystem.from_data(aqualink, data) assert r is not None assert isinstance(r, AqualinkPoolSystem)
async def get_systems(self) -> typing.Dict[str, AqualinkSystem]: r = await self._send_systems_request() data = await r.json() systems = [AqualinkSystem.from_data(self, x) for x in data] return {x.serial: x for x in systems if x is not None}