Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for cached state identify unsupported check #468

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homewizard_energy/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
70 changes: 70 additions & 0 deletions tests/v1/test_v1_homewizard_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down Expand Up @@ -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."""

Expand Down
Loading