Skip to content

Commit

Permalink
Added Gateway functions reboot() and factory_reset() (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
spektren authored and lwis committed Oct 13, 2017
1 parent 79cda2e commit a4c9e20
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions pytradfri/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def dump_devices():
print("> api(light.light_control.set_xy_color(254))")
print("> api(lights[1].light_control.set_dimmer(20))")
print("> tasks[0].repeat_days_list")
print("> api(gateway.reboot())")
print("> groups")
print("> moods")
print("> tasks")
Expand Down
5 changes: 4 additions & 1 deletion pytradfri/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ROOT_MOODS = "15005"
ROOT_SMART_TASKS = "15010"
ROOT_START_ACTION = "15013" # found under ATTR_START_ACTION
PATH_GATEWAY_INFO = ["15011", "15012"]
ROOT_GATEWAY = "15011"

ATTR_APPLICATION_TYPE = "5750"
ATTR_DEVICE_INFO = "3"
Expand All @@ -19,7 +19,10 @@
ATTR_CURRENT_TIME_UNIX = "9059"
ATTR_CURRENT_TIME_ISO8601 = "9060"
ATTR_FIRST_SETUP = "9069" # ??? unix epoch value when gateway first setup
ATTR_GATEWAY_INFO = "15012"
ATTR_GATEWAY_ID = "9081" # ??? id of the gateway
ATTR_GATEWAY_REBOOT = "9030" # gw reboot
ATTR_GATEWAY_FACTORY_DEFAULTS = "9031" # gw to factory defaults

ATTR_LIGHT_STATE = "5850" # 0 / 1
ATTR_LIGHT_DIMMER = "5851" # Dimmer, not following spec: 0..255
Expand Down
32 changes: 28 additions & 4 deletions pytradfri/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from .command import Command
from .const import (
ROOT_DEVICES, ROOT_GROUPS, ROOT_MOODS, ROOT_SMART_TASKS,
PATH_GATEWAY_INFO, ATTR_NTP, ATTR_FIRMWARE_VERSION,
ROOT_GATEWAY, ATTR_NTP, ATTR_FIRMWARE_VERSION,
ATTR_CURRENT_TIME_UNIX, ATTR_CURRENT_TIME_ISO8601,
ATTR_FIRST_SETUP, ATTR_GATEWAY_ID)
ATTR_FIRST_SETUP, ATTR_GATEWAY_INFO, ATTR_GATEWAY_ID,
ATTR_GATEWAY_REBOOT, ATTR_GATEWAY_FACTORY_DEFAULTS)
from .device import Device
from .group import Group
from .mood import Mood
Expand Down Expand Up @@ -83,7 +84,9 @@ def get_gateway_info(self):
def process_result(result):
return GatewayInfo(result)

return Command('get', PATH_GATEWAY_INFO, process_result=process_result)
return Command('get',
[ROOT_GATEWAY, ATTR_GATEWAY_INFO],
process_result=process_result)

def get_moods(self):
"""
Expand Down Expand Up @@ -150,6 +153,27 @@ def process_result(result):
return Command('get', [ROOT_SMART_TASKS, task_id],
process_result=process_result)

def reboot(self):
"""
Reboot the Gateway
Returns a Command.
"""

return Command('post',
[ROOT_GATEWAY, ATTR_GATEWAY_REBOOT])

def factory_reset(self):
"""
Resets the Gateway to factory defaults.
WARNING: All data in Gateway is lost (pairing, groups, etc)
Returns a Command.
"""

return Command('post',
[ROOT_GATEWAY, ATTR_GATEWAY_FACTORY_DEFAULTS])


class GatewayInfo:
"""This class contains Gateway information."""
Expand Down Expand Up @@ -191,7 +215,7 @@ def first_setup(self):

@property
def path(self):
return PATH_GATEWAY_INFO
return [ROOT_GATEWAY, ATTR_GATEWAY_INFO]

def set_values(self, values):
"""
Expand Down

0 comments on commit a4c9e20

Please sign in to comment.