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

Option to Skip Battery Devices on Refresh; Add Get_Engine_All Function #189

Merged
merged 6 commits into from
Feb 15, 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
37 changes: 35 additions & 2 deletions docs/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ reason string will be set to "refresh".
Supported: modem

The modem will send a refresh command to each device that it knows
about (i.e. devices defined in the config file). The command payload
about (i.e. devices defined in the config file). If the battery flag is false
or not present, battery operated devices will be skipped. The command payload
is:

```
{ "cmd" : "refresh_all", ["force" : true/false] }
{ "cmd" : "refresh_all", ["battery" : true/false, "force" : true/false] }
```


Expand All @@ -223,6 +224,38 @@ features are available on the device:
```


### Get device engine information

Supported: device

The engine version can be i1, i2, or i2cs. The engine version defines what
type of messages can be used with a device and the type of all link database
used by a device.

New Insteon devices purchased after 2018 are almost certainly all i2cs devices.
By default, we assume a device is i2cs.

If you have an older device that is not responding the the refresh command try
running get_engine and then try running refresh again. This only needs to be
run once on any device. The resulting information will be saved in the device
data.

```
{ "cmd" : "get_engine" }
```

### Get all device engines

Supported: modem

This will cause a get_engine command to be sent to each device (i.e. devices
defined in the config file). If the battery flag is false or not present,
battery operated devices will be skipped. The command payload is:

```
{ "cmd" : "get_engine", ["battery": true/false]}
```

### Add the device as a controller of another device.

Supported: modem, devices
Expand Down
44 changes: 43 additions & 1 deletion insteon_mqtt/Modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from . import log
from . import message as Msg
from . import util
from . import device as DevClass
from .Signal import Signal

LOG = log.get_logger()
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, protocol):
'print_db' : self.print_db,
'refresh' : self.refresh,
'refresh_all' : self.refresh_all,
'get_engine_all' : self.get_engine_all,
'linking' : self.linking,
'scene' : self.scene,
'factory_reset' : self.factory_reset,
Expand Down Expand Up @@ -292,7 +294,7 @@ def find(self, addr):
return device

#-----------------------------------------------------------------------
def refresh_all(self, force=False, on_done=None):
def refresh_all(self, battery=False, force=False, on_done=None):
"""Refresh all the all link databases.

This forces a refresh of the modem and device databases. This can
Expand All @@ -301,6 +303,8 @@ def refresh_all(self, force=False, on_done=None):
activity is expected on the network.

Args:
battery (bool): If true, will scan battery devices as well, by
default they are skipped.
force (bool): Force flag passed to devices. If True, devices
will refresh their Insteon db's even if they think the db
is up to date.
Expand All @@ -317,11 +321,49 @@ def refresh_all(self, force=False, on_done=None):

# Reload all the device databases.
for device in self.devices.values():
if not battery and isinstance(device, (DevClass.BatterySensor,
DevClass.Leak,
DevClass.Remote)):
LOG.ui("Refresh all, skipping battery device %s", device.label)
continue
seq.add(device.refresh, force)

# Start the command sequence.
seq.run()

#-----------------------------------------------------------------------
def get_engine_all(self, battery=False, on_done=None):
"""Run Get Engine on all the devices, except Modem

Devices are assumed to be i2cs, which all new devices are. If you
have a bunch of old devices, this can be a handy thing if you ever
lose your data directory. Otherwise you likely never need to use
this.

Args:
battery (bool): If True, will run on battery devices as well,
defaults to skipping them.
on_done: Finished callback. This is called when the command has
completed. Signature is: on_done(success, msg, data)
"""
# Set the error stop to false so a failed refresh doesn't stop the
# sequence from trying to refresh other devices.
seq = CommandSeq(self.protocol, "Get Engine all complete", on_done,
error_stop=False)

# Reload all the device databases.
for device in self.devices.values():
if not battery and isinstance(device, (DevClass.BatterySensor,
DevClass.Leak,
DevClass.Remote)):
LOG.ui("Get engine all, skipping battery device %s",
device.label)
continue
seq.add(device.get_engine)

# Start the command sequence.
seq.run()

#-----------------------------------------------------------------------
def get_devices(self, on_done=None):
""""Print all the devices the modem knows about to the log UI.
Expand Down
14 changes: 14 additions & 0 deletions insteon_mqtt/cmd_line/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,24 @@ def parse_args(args):
"in the configuration.")
sp.add_argument("-f", "--force", action="store_true",
help="Force the modem/device database to be downloaded.")
sp.add_argument("--battery", action="store_true",
help="Refresh battery devices too, by default they are "
"skipped.")
sp.add_argument("-q", "--quiet", action="store_true",
help="Don't print any command results to the screen.")
sp.set_defaults(func=modem.refresh_all)

#---------------------------------------
# modem.get_engine_all command
sp = sub.add_parser("get-engine-all", help="Call get-engine on the devices "
"in the configuration.")
sp.add_argument("--battery", action="store_true",
help="Run get-engine on battery devices too, by default "
"they are skipped.")
sp.add_argument("-q", "--quiet", action="store_true",
help="Don't print any command results to the screen.")
sp.set_defaults(func=modem.get_engine_all)

#---------------------------------------
# modem.factory_reset command
sp = sub.add_parser("factory-reset", help="Perform a remote factory "
Expand Down
13 changes: 13 additions & 0 deletions insteon_mqtt/cmd_line/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@ def refresh_all(args, config):
topic = "%s/modem" % (args.topic)
payload = {
"cmd" : "refresh_all",
"battery" : args.battery,
"force" : args.force,
}

reply = util.send(config, topic, payload, args.quiet)
return reply["status"]


#===========================================================================
def get_engine_all(args, config):
topic = "%s/modem" % (args.topic)
payload = {
"cmd" : "get_engine_all",
"battery" : args.battery,
}

reply = util.send(config, topic, payload, args.quiet)
return reply["status"]


#===========================================================================
def factory_reset(args, config):
topic = "%s/modem" % (args.topic)
Expand Down
2 changes: 1 addition & 1 deletion insteon_mqtt/device/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def get_model(self, on_done=None):
on_done: Finished callback. This is called when the command has
completed. Signature is: on_done(success, msg, data)
"""
LOG.info("Device %s cmd: get engine version", self.label)
LOG.info("Device %s cmd: get model", self.label)

# Send the get_engine_version request.
msg = Msg.OutStandard.direct(self.addr, 0x10, 0x00)
Expand Down