Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Name to Command Sequence Log #275

Merged
merged 2 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

- Catch and delay on PLM reporting busy. ([PR 261][P261])

- Tweak some of the logging to be more clear for users. ([PR 272][P272])
- Tweak some of the logging to be more clear for users. ([PR 272][P272] &
[PR 275][P275])

## [0.7.4]

Expand Down Expand Up @@ -494,3 +495,4 @@ will add new features.
[P268]: https://github.com/TD22057/insteon-mqtt/pull/268
[P272]: https://github.com/TD22057/insteon-mqtt/pull/272
[P201]: https://github.com/TD22057/insteon-mqtt/pull/201
[P275]: https://github.com/TD22057/insteon-mqtt/pull/275
9 changes: 6 additions & 3 deletions insteon_mqtt/CommandSeq.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class CommandSeq:
this library needs, it works ok.
"""
#-----------------------------------------------------------------------
def __init__(self, device, msg=None, on_done=None, error_stop=True):
def __init__(self, device, msg=None, on_done=None, error_stop=True,
name=""):
"""Constructor

Args:
Expand All @@ -37,13 +38,15 @@ def __init__(self, device, msg=None, on_done=None, error_stop=True):
when there is an error or when all the commands finish.
error_stop (bool): True to stop the sequence if a command fails.
False to continue on with the sequence.
name (str): A short name used in logging to identify this sequence
"""
self.device = device

self._on_done = util.make_callback(on_done)
self.msg = msg
self.error_stop = error_stop
self.total = 0
self.name = name

# List of Entry objects (see class below) to call for each step in
# the sequence.
Expand Down Expand Up @@ -125,8 +128,8 @@ def on_done(self, success, msg, data):

# Otherwise run the next command.
else:
LOG.debug("Running command %d of %d", self.total + 1 -
len(self.calls), self.total)
LOG.debug("CmdSeq %s Running %d of %d", self.name,
self.total + 1 - len(self.calls), self.total)

entry = self.calls.pop(0)
entry.run(self.device, self.on_done)
Expand Down
13 changes: 7 additions & 6 deletions insteon_mqtt/Modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def refresh_all(self, battery=False, force=False, on_done=None):
# Set the error stop to false so a failed refresh doesn't stop the
# sequence from trying to refresh other devices.
seq = CommandSeq(self, "Refresh all complete", on_done,
error_stop=False)
error_stop=False, name="RefreshAll")

# Reload the modem database.
seq.add(self.refresh, force)
Expand Down Expand Up @@ -375,7 +375,7 @@ def get_engine_all(self, battery=False, on_done=None):
# Set the error stop to false so a failed refresh doesn't stop the
# sequence from trying to refresh other devices.
seq = CommandSeq(self, "Get Engine all complete", on_done,
error_stop=False)
error_stop=False, name="EngineAll")

# Reload all the device databases.
for device in self.devices.values():
Expand Down Expand Up @@ -671,7 +671,7 @@ def sync(self, dry_run=True, refresh=True, sequence=None, on_done=None):
seq = sequence
else:
seq = CommandSeq(self, "Sync complete", on_done,
error_stop=False)
error_stop=False, name="ModemSync")

if refresh:
LOG.ui("Performing DB Refresh of %s device", self.label)
Expand Down Expand Up @@ -736,7 +736,7 @@ def sync_all(self, dry_run=True, refresh=True, on_done=None):
# Set the error stop to false so a failed refresh doesn't stop the
# sequence from trying to refresh other devices.
seq = CommandSeq(self, "Sync All complete", on_done,
error_stop=False)
error_stop=False, name="SyncAll")

# First the modem database.
seq.add(self.sync, dry_run=dry_run, refresh=refresh)
Expand Down Expand Up @@ -1165,7 +1165,8 @@ def _db_update(self, local_group, is_controller, remote_addr, remote_group,
# discussion.
local_data = self.link_data(is_controller, local_group, local_data)

seq = CommandSeq(self, "Device db update complete", on_done)
seq = CommandSeq(self, "Device db update complete", on_done,
name="ModemDBUpd")

# Create a new database entry for the modem and send it to the modem
# for updating.
Expand Down Expand Up @@ -1223,7 +1224,7 @@ def _db_delete(self, addr, group, is_controller, two_way, refresh,
return

# Add the function delete call to the sequence.
seq = CommandSeq(self, "Delete complete", on_done)
seq = CommandSeq(self, "Delete complete", on_done, name="ModemDBDel")
seq.add(self.db.delete_on_device, entry)

# For two way commands, insert a callback so that when the modem
Expand Down
2 changes: 1 addition & 1 deletion insteon_mqtt/db/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def _add_using_new(self, addr, group, is_controller, data,
# pylint: disable=too-many-locals

seq = CommandSeq(self.device, "Device database update complete",
on_done)
on_done, name="DbAddNew")

last_mem_loc = self.last.mem_loc

Expand Down
14 changes: 8 additions & 6 deletions insteon_mqtt/device/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def join(self, on_done=None):
LOG.info("Join Device %s", self.addr)

# Using a sequence so we can pass the on_done function through.
seq = CommandSeq(self, "Device joined.", on_done)
seq = CommandSeq(self, "Device joined.", on_done, name="JoinSequence")

# First get the engine version. This process only works and is
# necessary on I2CS devices.
Expand Down Expand Up @@ -299,7 +299,7 @@ def _join_device(self, on_done=None):
return
else:
# Build a sequence of calls to do the link.
seq = CommandSeq(self, "Operation Complete", on_done)
seq = CommandSeq(self, "Join Complete", on_done, name="JoinDevice")

# Put Modem in linking mode first
seq.add(self.modem.linking)
Expand Down Expand Up @@ -377,7 +377,8 @@ def refresh(self, force=False, on_done=None):
LOG.info("Device %s cmd: status refresh", self.label)

# Use a sequence
seq = CommandSeq(self, "Device refreshed", on_done)
seq = CommandSeq(self, "Device refreshed", on_done,
name="DeviceRefresh")

# This sends a refresh ping which will respond w/ the current
# database delta field. The handler checks that against the
Expand Down Expand Up @@ -515,7 +516,7 @@ def sync(self, dry_run=True, refresh=True, sequence=None, on_done=None):
seq = sequence
else:
seq = CommandSeq(self, "Sync complete", on_done,
error_stop=False)
error_stop=False, name="DeviceSync")

if refresh:
LOG.ui("Performing DB Refresh of %s device", self.label)
Expand Down Expand Up @@ -1112,7 +1113,8 @@ def _db_update(self, local_group, is_controller, remote_addr, remote_group,
"Link will be only one direction",
util.ctrl_str(is_controller), remote_addr)

seq = CommandSeq(self, "Device db update complete", on_done)
seq = CommandSeq(self, "Device db update complete", on_done,
name="DeviceDBUpdate")

# Check for a db update - otherwise we could be out of date and not
# know it in which case the memory addresses to add the record in
Expand Down Expand Up @@ -1176,7 +1178,7 @@ def _db_delete(self, addr, group, is_controller, two_way, refresh,
on_done(False, "Entry doesn't exist", None)
return

seq = CommandSeq(self, "Delete complete", on_done)
seq = CommandSeq(self, "Delete complete", on_done, name="DeviceDBDel")

# Check for a db update - otherwise we could be out of date and not
# know it in which case the memory addresses to add the record in
Expand Down
2 changes: 1 addition & 1 deletion insteon_mqtt/device/BatterySensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "BatterySensor paired", on_done)
seq = CommandSeq(self, "BatterySensor paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down
5 changes: 3 additions & 2 deletions insteon_mqtt/device/Dimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "Dimmer paired", on_done)
seq = CommandSeq(self, "Dimmer paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -588,7 +588,8 @@ def set_flags(self, on_done, **kwargs):
"are: %s" % unknown, flags)

# Start a command sequence so we can call the flag methods in series.
seq = CommandSeq(self, "Dimmer set_flags complete", on_done)
seq = CommandSeq(self, "Dimmer set_flags complete", on_done,
name="SetFlags")

if FLAG_BACKLIGHT in kwargs:
backlight = util.input_byte(kwargs, FLAG_BACKLIGHT)
Expand Down
6 changes: 4 additions & 2 deletions insteon_mqtt/device/EZIO4O.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self.protocol, "EZIO4O paired", on_done)
seq = CommandSeq(self.protocol, "EZIO4O paired", on_done,
name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -189,7 +190,8 @@ def refresh(self, force=False, on_done=None):
LOG.info("EZIO4O %s cmd: status refresh", self.label)

# NOTE: EZIO4O cmd1=0x4F cmd2=0x02 will report the output state.
seq = CommandSeq(self.protocol, "Device refreshed", on_done)
seq = CommandSeq(self.protocol, "Device refreshed", on_done,
name="DevRefresh")

# This sends a refresh ping which will respond w/ the current
# database delta field. The handler checks that against the current
Expand Down
4 changes: 2 additions & 2 deletions insteon_mqtt/device/FanLinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "FanLinc paired", on_done)
seq = CommandSeq(self, "FanLinc paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -147,7 +147,7 @@ def refresh(self, force=False, on_done=None):
"""
LOG.info("Device %s cmd: fan status refresh", self.addr)

seq = CommandSeq(self, "Refresh complete", on_done)
seq = CommandSeq(self, "Refresh complete", on_done, name="DevRefresh")

# Send a 0x19 0x03 command to get the fan speed level. This sends a
# refresh ping which will respond w/ the fan level and current
Expand Down
10 changes: 6 additions & 4 deletions insteon_mqtt/device/IOLinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "IOLinc paired", on_done)
seq = CommandSeq(self, "IOLinc paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -323,7 +323,8 @@ def get_flags(self, on_done=None):
"""
LOG.info("IOLinc %s cmd: get operation flags", self.label)

seq = CommandSeq(self.protocol, "IOlinc get flags done", on_done)
seq = CommandSeq(self.protocol, "IOlinc get flags done", on_done,
name="GetFlags")

# This sends a refresh ping which will respond w/ the current
# database delta field. The handler checks that against the
Expand Down Expand Up @@ -374,7 +375,8 @@ def set_flags(self, on_done, **kwargs):
raise Exception("Unknown IOLinc flags input: %s.\n Valid flags " +
"are: %s" % unknown, flags)

seq = CommandSeq(self.protocol, "Device flags set", on_done)
seq = CommandSeq(self.protocol, "Device flags set", on_done,
name="SetFLags")

# Loop through flags, sending appropriate command for each flag
for flag in kwargs:
Expand Down Expand Up @@ -501,7 +503,7 @@ def refresh(self, force=False, on_done=None):

# NOTE: IOLinc cmd1=0x00 will report the relay state. cmd2=0x01
# reports the sensor state which is what we want.
seq = CommandSeq(self, "Device refreshed", on_done)
seq = CommandSeq(self, "Device refreshed", on_done, name="DevRefresh")

# This sends a refresh ping which will respond w/ the current
# database delta field. The handler checks that against the current
Expand Down
9 changes: 5 additions & 4 deletions insteon_mqtt/device/KeypadLinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "KeypadLinc paired", on_done)
seq = CommandSeq(self, "KeypadLinc paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -206,7 +206,7 @@ def refresh(self, force=False, on_done=None):
# Send a 0x19 0x01 command to get the LED light on/off flags.
LOG.info("KeypadLinc %s cmd: keypad status refresh", self.addr)

seq = CommandSeq(self, "Refresh complete", on_done)
seq = CommandSeq(self, "Refresh complete", on_done, name="DevRefresh")

# TODO: change this to 0x2e get extended which reads on mask, off
# mask, on level, led brightness, non-toggle mask, led bit mask (led
Expand Down Expand Up @@ -791,7 +791,8 @@ def set_backlight(self, level, on_done=None):

# Otherwise use the level changing command.
else:
seq = CommandSeq(self, "Backlight level", on_done)
seq = CommandSeq(self, "Backlight level", on_done,
name="SetBacklight")

# Bound to 0x11 <= level <= 0x7f per page 157 of insteon dev guide.
level = max(0x11, min(level, 0x7f))
Expand Down Expand Up @@ -953,7 +954,7 @@ def set_flags(self, on_done, **kwargs):

# Start a command sequence so we can call the flag methods in series.
seq = CommandSeq(self, "KeypadLinc set_flags complete",
on_done)
on_done, name="SetFlags")

# Get the group if it was set.
group = util.input_integer(kwargs, FLAG_GROUP)
Expand Down
2 changes: 1 addition & 1 deletion insteon_mqtt/device/Leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "LeakSensor paired", on_done)
seq = CommandSeq(self, "LeakSensor paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down
3 changes: 2 additions & 1 deletion insteon_mqtt/device/Motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def set_flags(self, on_done, **kwargs):
raise Exception("Unknown Motion flags input: %s.\n Valid flags "
"are: %s" % (unknown, flags))

seq = CommandSeq(self, "Motion Set Flags Success", on_done)
seq = CommandSeq(self, "Motion Set Flags Success", on_done,
name="SetFlags")

# For some flags we need to know the existing bit before we change it.
# So to insure that we are starting from the correct values, get the
Expand Down
7 changes: 4 additions & 3 deletions insteon_mqtt/device/Outlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "Outlet paired", on_done)
seq = CommandSeq(self, "Outlet paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -145,7 +145,7 @@ def refresh(self, force=False, on_done=None):
"""
LOG.info("Outlet %s cmd: status refresh", self.label)

seq = CommandSeq(self, "Device refreshed", on_done)
seq = CommandSeq(self, "Device refreshed", on_done, name="DevRefresh")

# This sends a refresh ping which will respond w/ the current
# database delta field. The handler checks that against the current
Expand Down Expand Up @@ -414,7 +414,8 @@ def set_flags(self, on_done, **kwargs):
"are: %s" % unknown, flags)

# Start a command sequence so we can call the flag methods in series.
seq = CommandSeq(self, "Outlet set_flags complete", on_done)
seq = CommandSeq(self, "Outlet set_flags complete", on_done,
name="DevSetFlags")

if FLAG_BACKLIGHT in kwargs:
backlight = util.input_byte(kwargs, FLAG_BACKLIGHT)
Expand Down
2 changes: 1 addition & 1 deletion insteon_mqtt/device/Remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "Remote paired", on_done)
seq = CommandSeq(self, "Remote paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down
4 changes: 2 additions & 2 deletions insteon_mqtt/device/SmokeBridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def pair(self, on_done=None):
# call finishes and works before calling the next one. We have to do
# this for device db manipulation because we need to know the memory
# layout on the device before making changes.
seq = CommandSeq(self, "SmokeBridge paired", on_done)
seq = CommandSeq(self, "SmokeBridge paired", on_done, name="DevPair")

# Start with a refresh command - since we're changing the db, it must
# be up to date or bad things will happen.
Expand Down Expand Up @@ -130,7 +130,7 @@ def refresh(self, force=False, on_done=None):
"""
LOG.info("Smoke bridge %s cmd: status refresh", self.addr)

seq = CommandSeq(self, "Device refreshed", on_done)
seq = CommandSeq(self, "Device refreshed", on_done, name="DevRefresh")

# There is no way to get the current device status but we can request
# the all link database delta so get that. See smoke bridge dev
Expand Down
Loading