Skip to content

Commit

Permalink
Require libs to implement probe method.
Browse files Browse the repository at this point in the history
ControllerApplication.probe() method receives SCHEMA_DEVICE as config
and should return True if radio was successfuly detected or False
otherwise.
  • Loading branch information
Adminiuga committed Apr 19, 2020
1 parent 22c9314 commit c728e57
Show file tree
Hide file tree
Showing 3 changed files with 15 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
7 changes: 6 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 Down Expand Up @@ -398,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 c728e57

Please sign in to comment.