Skip to content

Commit

Permalink
Added --json argument per issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterWil committed Aug 25, 2017
1 parent 5c0d8ee commit a8a5cd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Simple command line implementation arguments::
--set setting=value Set setting to a value
--devices Output all devices
--device device_id Output one device for device_id
--json device_id Output the json for device_id
--on device_id Switch on a given device_id
--off device_id Switch off a given device_id
--lock device_id Lock a given device_id
Expand Down
20 changes: 19 additions & 1 deletion abodepy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Abode's servers. Leverage the cloud push event notification functionality as
much as possible. Please use this module responsibly.
"""

import json
import logging
import time

Expand Down Expand Up @@ -104,6 +104,12 @@ def get_arguments():
help='Output one device for device_id',
required=False, action='append')

parser.add_argument(
'--json',
metavar='device_id',
help='Output the json for device_id',
required=False, action='append')

parser.add_argument(
'--on',
metavar='device_id',
Expand Down Expand Up @@ -225,6 +231,18 @@ def call():
else:
_LOGGER.warning("Could not find device with id: %s", device_id)

# Output Json
for device_id in args.json or []:
device = abode.get_device(device_id)

if device:
# pylint: disable=protected-access
_LOGGER.info(device_id + " JSON:\n" +
json.dumps(device._json_state, sort_keys=True,
indent=4, separators=(',', ': ')))
else:
_LOGGER.warning("Could not find device with id: %s", device_id)

# Print
def _device_print(dev, append=''):
_LOGGER.info("Device Name: %s, ID: %s, Type: %s, Status: %s%s",
Expand Down

0 comments on commit a8a5cd3

Please sign in to comment.