diff --git a/homewizard_energy/v1/__init__.py b/homewizard_energy/v1/__init__.py index 807dcfc..3147e4f 100644 --- a/homewizard_energy/v1/__init__.py +++ b/homewizard_energy/v1/__init__.py @@ -96,7 +96,7 @@ async def state( ) -> State: """Return or update the state object.""" - if self._device is not None and self._device.supports_state is False: + if self._device is not None and self._device.supports_state() is False: raise UnsupportedError("State is not supported") if power_on is not None or switch_lock is not None or brightness is not None: @@ -119,7 +119,7 @@ async def identify( ) -> bool: """Send identify request.""" - if self._device is not None and self._device.supports_state is False: + if self._device is not None and self._device.supports_identify() is False: raise UnsupportedError("State is not supported") await self._request("api/v1/identify", method=METH_PUT) diff --git a/tests/v1/test_v1_homewizard_energy.py b/tests/v1/test_v1_homewizard_energy.py index 123caa8..3914900 100644 --- a/tests/v1/test_v1_homewizard_energy.py +++ b/tests/v1/test_v1_homewizard_energy.py @@ -595,6 +595,42 @@ async def test_state_set( await api.close() +@pytest.mark.parametrize( + "model", + [ + "HWE-P1", + "HWE-WTR", + "HWE-KWH1", + "HWE-KWH3", + "SDM230-wifi", + "SDM630-wifi", + ], +) +async def test_state_not_supported_with_cached_device(aresponses, model: str): + """Test state set uses cached device to check is unsupported.""" + + aresponses.add( + "example.com", + "/api", + "GET", + aresponses.Response( + text=load_fixtures(f"{model}/device.json"), + status=200, + headers={"Content-Type": "application/json; charset=utf-8"}, + ), + ) + + async with aiohttp.ClientSession() as session: + api = HomeWizardEnergyV1("example.com", clientsession=session) + + await api.device() + + with pytest.raises(UnsupportedError): + await api.state() + + await api.close() + + @pytest.mark.parametrize( "model", [ @@ -670,6 +706,40 @@ async def test_identify_not_supported(model: str, aresponses): await api.close() +@pytest.mark.parametrize( + "model", + [ + "HWE-KWH1", + "HWE-KWH3", + "SDM230-wifi", + "SDM630-wifi", + ], +) +async def test_identify_not_supported_with_cached_device(aresponses, model: str): + """Test identify set uses cached device to check is unsupported.""" + + aresponses.add( + "example.com", + "/api", + "GET", + aresponses.Response( + text=load_fixtures(f"{model}/device.json"), + status=200, + headers={"Content-Type": "application/json; charset=utf-8"}, + ), + ) + + async with aiohttp.ClientSession() as session: + api = HomeWizardEnergyV1("example.com", clientsession=session) + + await api.device() + + with pytest.raises(UnsupportedError): + await api.identify() + + await api.close() + + async def test_get_system_object(aresponses): """Test fetches system object and device object when unknown."""