Skip to content

Commit

Permalink
Test for device class by type vs isinstance (#113)
Browse files Browse the repository at this point in the history
* Test for device class by type vs isinstance

* Pin aiohttp as there seems to be a bug in the latest version

* Add note about aiohttp

* Bump version
  • Loading branch information
kingsleyadam authored Nov 14, 2024
1 parent 59a57d2 commit 30184ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages = ["src/abbfreeathome"]

[project]
name = "local-abbfreeathome"
version = "1.14.0"
version = "1.14.1"
authors = [
{ name="Adam Kingsley", email="[email protected]" },
]
Expand Down
5 changes: 4 additions & 1 deletion src/abbfreeathome/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
aiohttp
# There's an issue with aioresponses and the latest version of aiohttp
# Pin an earlier version for development until PR is merged and released.
# https://github.com/pnuckowski/aioresponses/pull/262
aiohttp<3.11.0
pytest
pytest-asyncio
pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion src/abbfreeathome/freeathome.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_devices_by_class(self, device_class: Base) -> list[Base]:
return [
_device
for _device in self._devices.values()
if isinstance(_device, device_class)
if type(_device) is device_class
]

async def get_devices_by_function(self, function: Function) -> list[dict]:
Expand Down
9 changes: 5 additions & 4 deletions tests/test_freeathome.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ async def test_get_room_name(freeathome):
assert room_name is None


def test_get_device_by_class(freeathome):
@pytest.mark.asyncio
async def test_get_device_by_class(freeathome):
"""Test the get_device_class function."""
device = MagicMock(spec=SwitchActuator)
freeathome._devices = {"device1": device}
await freeathome.load_devices()

devices = freeathome.get_devices_by_class(SwitchActuator)
assert devices == [device]
assert len(devices) == 2


@pytest.mark.asyncio
Expand Down

0 comments on commit 30184ee

Please sign in to comment.