Skip to content

Commit

Permalink
Require radio libs to implement probe() method for ControllerApplicat…
Browse files Browse the repository at this point in the history
…ion class (zigpy#383)

* CONFIG and DEVICE schemas as attributes of Controller app.

* Require libs to implement probe method.

ControllerApplication.probe() method receives SCHEMA_DEVICE as config
and should return True if radio was successfuly detected or False
otherwise.
  • Loading branch information
Adminiuga authored and puddly committed Jul 11, 2020
1 parent 97d8814 commit 1b29509
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/test_appdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async def request(
async def permit_ncp(self, time_s=60):
pass

async def probe(self, config):
return True

with mock.patch("zigpy.ota.OTA.initialize", CoroutineMock()):
app = await App.new(ZIGPY_SCHEMA({CONF_DATABASE: database_file}))
return app
Expand Down
6 changes: 6 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async def request(
async def permit_ncp(self, time_s=60):
pass

async def probe(self, config):
return True

return App({CONF_DATABASE: None})


Expand Down Expand Up @@ -99,6 +102,9 @@ async def request(
async def permit_ncp(self, time_s=60):
pass

async def probe(self, config):
return True

p1 = mock.patch.object(App, "_load_db", CoroutineMock())
p2 = mock.patch.object(App, "startup", CoroutineMock())
p3 = mock.patch.object(App, "shutdown", CoroutineMock())
Expand Down
10 changes: 9 additions & 1 deletion zigpy/application.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import asyncio
import logging
from typing import Dict, Optional
from typing import Any, Dict, Optional

import zigpy.appdb
import zigpy.config
Expand All @@ -20,6 +20,9 @@


class ControllerApplication(zigpy.util.ListenableMixin, abc.ABC):
SCHEMA = zigpy.config.CONFIG_SCHEMA
SCHEMA_DEVICE = zigpy.config.SCHEMA_DEVICE

def __init__(self, config: Dict):
self._send_sequence = 0
self.devices: Dict[t.EUI64, zigpy.device.Device] = {}
Expand Down Expand Up @@ -395,3 +398,8 @@ def ota(self):
def pan_id(self):
"""Network PAN Id."""
return self._pan_id

@classmethod
@abc.abstractmethod
async def probe(cls, device_config: Dict[str, Any]) -> bool:
"""API/Port probe method."""

0 comments on commit 1b29509

Please sign in to comment.