Skip to content

Commit

Permalink
fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Oct 13, 2024
1 parent 204052a commit 69af6f3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 37 deletions.
24 changes: 6 additions & 18 deletions examples/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,7 @@ async def main() -> None:
async with Controller("ws://localhost:8001/") as controller:
await controller.clients.listen()

await controller.network.start_network(
{
"radio_type": "ezsp",
"device": {
"path": "/dev/cu.GoControl_zigbee\u0011",
"flow_control": "software",
"baudrate": 57600,
},
"database_path": "./zigbee.db",
"enable_quirks": True,
"message_id": 1,
}
)
await controller.network.start_network()

await controller.load_devices()
await controller.load_groups()
Expand Down Expand Up @@ -94,7 +82,7 @@ async def main() -> None:

await asyncio.sleep(3)
except Exception as err:
_LOGGER.exception(exc_info=err)
_LOGGER.exception("Exception testing lights", exc_info=err)

if test_switches:
try:
Expand All @@ -116,7 +104,7 @@ async def main() -> None:

await asyncio.sleep(3)
except Exception as err:
_LOGGER.exception(exc_info=err)
_LOGGER.exception("Exception testing switches", exc_info=err)

if test_alarm_control_panel:
try:
Expand All @@ -130,7 +118,7 @@ async def main() -> None:

await asyncio.sleep(3)
except Exception as err:
_LOGGER.exception(exc_info=err)
_LOGGER.exception("Exception testing alarm control panel", exc_info=err)

if test_locks:
try:
Expand All @@ -146,7 +134,7 @@ async def main() -> None:

await asyncio.sleep(3)
except Exception as err:
_LOGGER.exception(exc_info=err)
_LOGGER.exception("Exception testing locks", exc_info=err)

if test_buttons:
try:
Expand All @@ -158,7 +146,7 @@ async def main() -> None:

await asyncio.sleep(3)
except Exception as err:
_LOGGER.exception(exc_info=err)
_LOGGER.exception("Exception testing buttons", exc_info=err)

"""TODO turn this into an example for how to create a group with the client
await controller.groups_helper.create_group(
Expand Down
3 changes: 3 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import zigpy.zcl
import zigpy.zcl.foundation as zcl_f

from zha.application.discovery import Platform
from zha.zigbee import Device, Group
from zhaws.client.model.types import BasePlatformEntity
from zhaws.client.proxy import DeviceProxy
from zhaws.server.websocket.server import Server
Expand Down Expand Up @@ -203,6 +205,7 @@ def find_entity_id(
for entity_id in entities:
if qualifier in entity_id:
return entity_id
return None
else:
return entities[0]

Expand Down
18 changes: 7 additions & 11 deletions tests/test_client_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_group_entity(
for entity in group_proxy.group_model.entities.values()
}

return entities.get(entity_id) # type: ignore
return entities.get(entity_id)


@pytest.fixture
Expand Down Expand Up @@ -141,7 +141,7 @@ async def test_controller_devices(

client_device: Optional[DeviceProxy] = controller.devices.get(zha_device.ieee)
assert client_device is not None
entity: SwitchEntity = get_entity(client_device, entity_id) # type: ignore
entity: SwitchEntity = get_entity(client_device, entity_id)
assert entity is not None

assert isinstance(entity, SwitchEntity)
Expand Down Expand Up @@ -176,7 +176,7 @@ async def test_controller_devices(
assert len(controller.devices) == 1

# we removed and joined the device again so lets get the entity again
client_device: Optional[DeviceProxy] = controller.devices.get(zha_device.ieee)
client_device = controller.devices.get(zha_device.ieee)
assert client_device is not None
entity: SwitchEntity = get_entity(client_device, entity_id) # type: ignore
assert entity is not None
Expand Down Expand Up @@ -330,14 +330,14 @@ async def test_controller_groups(
assert client_device1 is not None
entity_id1 = find_entity_id(Platform.SWITCH, device_switch_1)
assert entity_id1 is not None
entity1: SwitchEntity = get_entity(client_device1, entity_id1) # type: ignore
entity1: SwitchEntity = get_entity(client_device1, entity_id1)
assert entity1 is not None

client_device2: Optional[DeviceProxy] = controller.devices.get(device_switch_2.ieee)
assert client_device2 is not None
entity_id2 = find_entity_id(Platform.SWITCH, device_switch_2)
assert entity_id2 is not None
entity2: SwitchEntity = get_entity(client_device2, entity_id2) # type: ignore
entity2: SwitchEntity = get_entity(client_device2, entity_id2)
assert entity2 is not None

response: GroupModel = await controller.groups_helper.create_group(
Expand All @@ -351,9 +351,7 @@ async def test_controller_groups(
assert client_device2.device_model.ieee in response.members

# test remove member from group from controller
response: GroupModel = await controller.groups_helper.remove_group_members(
response, [entity2]
)
response = await controller.groups_helper.remove_group_members(response, [entity2])
await server.block_till_done()
assert len(controller.groups) == 2
assert response.id in controller.groups
Expand All @@ -362,9 +360,7 @@ async def test_controller_groups(
assert client_device2.device_model.ieee not in response.members

# test add member to group from controller
response: GroupModel = await controller.groups_helper.add_group_members(
response, [entity2]
)
response = await controller.groups_helper.add_group_members(response, [entity2])
await server.block_till_done()
assert len(controller.groups) == 2
assert response.id in controller.groups
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ async def test_server_client_connect_disconnect(
assert client._listen_task is not None

# The listen task is automatically stopped when we disconnect
assert client._listen_task is None # type: ignore
assert client._listen_task is None
assert "not connected" in repr(client)
assert not client.connected

assert not server.is_serving # type: ignore
assert not server.is_serving
assert server._ws_server is None


Expand Down
3 changes: 1 addition & 2 deletions zhaws/server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
async def main(config_path: str | None = None) -> None:
"""Run the websocket server."""
if config_path is None:
_LOGGER.info("No config file provided, using default configuration")
configuration = ServerConfiguration()
raise ValueError("config_path must be provided")
else:
_LOGGER.info("Loading configuration from %s", config_path)
path = Path(config_path)
Expand Down
2 changes: 1 addition & 1 deletion zhaws/server/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class PlatformEntityCommand(WebSocketCommand):
"""Base class for platform entity commands."""

ieee: Union[EUI64, None]
group_id: Union[int, None]
group_id: Union[int, None] = None
unique_id: str
2 changes: 1 addition & 1 deletion zhaws/server/platforms/alarm_control_panel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TriggerAlarmCommand(PlatformEntityCommand):
command: Literal[APICommands.ALARM_CONTROL_PANEL_TRIGGER] = (
APICommands.ALARM_CONTROL_PANEL_TRIGGER
)
code: Union[str, None]
code: Union[str, None] = None


@decorators.websocket_command(TriggerAlarmCommand)
Expand Down
6 changes: 4 additions & 2 deletions zhaws/server/websocket/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ async def block_till_done(self) -> None:

async def _await_and_log_pending(self, pending: Iterable[Awaitable[Any]]) -> None:
"""Await and log tasks that take a long time."""
# pylint: disable=no-self-use
wait_time = 0
while pending:
_, pending = await asyncio.wait(pending, timeout=BLOCK_LOG_TIMEOUT)
_, pending = await asyncio.wait(
[asyncio.ensure_future(task) for task in pending],
timeout=BLOCK_LOG_TIMEOUT,
)
if not pending:
return
wait_time += BLOCK_LOG_TIMEOUT
Expand Down

0 comments on commit 69af6f3

Please sign in to comment.