Skip to content

Commit

Permalink
improved watchdog (#14)
Browse files Browse the repository at this point in the history
* style fix

* style fix

* style fix

* improved watchdog
  • Loading branch information
Yoda-x authored Nov 27, 2018
1 parent 38ce26f commit 76e7019
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions bellows/cli/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""CLI commands which use the application framework"""
"""CLI commands which use the application framework."""

import asyncio
import binascii
Expand Down Expand Up @@ -80,7 +80,7 @@ async def inner(ctx):
@opts.database_file
@click.pass_context
def devices(ctx, database):
"""Show device database"""
"""Show device database."""

def print_clusters(title, clusters):
clusters = sorted(list(clusters.items()))
Expand Down Expand Up @@ -120,7 +120,7 @@ def print_clusters(title, clusters):
@opts.database_file
@click.argument('node', type=util.ZigbeeNodeParamType())
def zdo(ctx, node, database):
"""Perform ZDO operations against a device"""
"""Perform ZDO operations against a device."""
ctx.obj['node'] = node
ctx.obj['database_file'] = database

Expand Down Expand Up @@ -218,7 +218,7 @@ async def leave(ctx):
@click.argument('endpoint', type=click.IntRange(1, 255))
@click.argument('cluster', type=click.IntRange(0, 65535))
def zcl(ctx, database, node, cluster, endpoint):
"""Peform ZCL operations against a device"""
"""Peform ZCL operations against a device."""
ctx.obj['database_file'] = database
ctx.obj['node'] = node
ctx.obj['endpoint'] = endpoint
Expand Down
2 changes: 1 addition & 1 deletion bellows/cli/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
@click.pass_context
def dump(ctx, channel, outfile):
"""Capture frames on CHANNEL and write to FILE in tcpdump format"""
"""Capture frames on CHANNEL and write to FILE in tcpdump format."""
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(_dump(ctx, channel, outfile))
Expand Down
2 changes: 1 addition & 1 deletion bellows/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def network_init(s):


def parse_epan(epan):
"""Parse a user specified extended PAN ID"""
"""Parse a user specified extended PAN ID."""
epan_list = [t.uint8_t(x, 16) for x in epan.split(":")]
return t.fixed_list(8, t.uint8_t)(epan_list)

Expand Down
4 changes: 2 additions & 2 deletions bellows/ezsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _ezsp_frame(self, name, *args):

return bytes(frame) + data

async def _command(self, name, *args, queue = True):
async def _command(self, name, *args, queue=True):
LOGGER.debug("Send command %s", name)
data = self._ezsp_frame(name, *args)
c = self.COMMANDS[name]
Expand All @@ -83,7 +83,7 @@ async def _command(self, name, *args, queue = True):
LOGGER.debug("catched:%s", e)
return
else:
await self._gw.data_noqueue(data)
await self._gw.data_noqueue(data)
await future
return future.result()

Expand Down
1 change: 1 addition & 0 deletions bellows/types/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ class EmberGpSinkListEntry(EzspStruct):
('sinkNodeId', named.EmberNodeId),
]


class EmberEndpoint(EzspStruct):
# Ember endpoint
_fields = [
Expand Down
4 changes: 2 additions & 2 deletions bellows/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def __init__(self, application, connected_future=None):
self._task_send_task = None

def status(self):
return [self._failed_mode,
return [bool(self._failed_mode),
self._task_send_task.done(),
not self._Run_Event.is_set(),
]
]

def connection_made(self, transport):
"""Callback when the uart is connected."""
Expand Down
17 changes: 10 additions & 7 deletions bellows/zigbee/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import asyncio, binascii, logging, os
import asyncio
import binascii
import logging
import os
from zigpy.exceptions import DeliveryError
import zigpy.application
import zigpy.device
Expand Down Expand Up @@ -30,19 +33,19 @@ def __init__(self, ezsp, database_file=None):

def status(self):
return [self._ezsp.status(), [
self._startup,
self._startup,
self._watchdog_task.done(),
self._pull_frames_task.done()]
]
]

async def _watchdog(self, wakemeup=60):
"""run in background, checks if uart restart hangs and restart as needed."""
while True:
try:
await asyncio.sleep(wakemeup)
LOGGER.debug("watchdog: running")
if self._startup:
LOGGER.error("watchdog: startup running, restart ")
if self._startup or bool(sum(self._ezsp.status())):
LOGGER.error("watchdog: startup running or failed uart restart ")
if self._startup_task and not self._startup_task.done():
self._startup_task.cancel()
LOGGER.info("watchdog: cancel startup task ")
Expand All @@ -53,7 +56,7 @@ async def _watchdog(self, wakemeup=60):
self._startup = False
self._startup_task = asyncio.ensure_future(self._startup())
except Exception as e:
LOGGER.debug("watchdog: catched %s", e)
LOGGER.info("watchdog: catched %s", e)

async def initialize(self):
"""Perform basic NCP initialization steps."""
Expand Down Expand Up @@ -265,7 +268,7 @@ def _handle_reply(self, sender, aps_frame, tsn, command_id, args):
except KeyError:
LOGGER.warning("0x%04x:%s:0x%04x Unexpected response TSN=%s command=%s args=%s ",
sender.nwk, aps_frame.sourceEndpoint, aps_frame.clusterId,
tsn, command_id, args )
tsn, command_id, args)
except asyncio.futures.InvalidStateError as exc:
LOGGER.debug("Invalid state on future - probably duplicate response: %s", exc)
# We've already handled, don't drop through to device handler
Expand Down

0 comments on commit 76e7019

Please sign in to comment.