Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #155 from elmigbot/master
Browse files Browse the repository at this point in the history
Added the new Lutron Aurora Switches
  • Loading branch information
robmarkcole authored Nov 19, 2019
2 parents dd37745 + d1a51da commit 44db87f
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions custom_components/huesensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"ROM": "mdi:remote",
"ZGP": "mdi:remote",
"FOH": "mdi:light-switch",
"Z3-": "mdi:light-switch",
}
DEVICE_CLASSES = {"SML": "motion"}
ATTRS = {
Expand All @@ -47,6 +48,14 @@
"ROM": ["last_updated", "battery", "on", "reachable"],
"ZGP": ["last_updated"],
"FOH": ["last_updated"],
"Z3-": ["last_updated",
"battery",
"on",
"reachable",
"dial_state",
"dial_position",
"software_update",
],
}


Expand All @@ -68,6 +77,20 @@ def parse_hue_api_response(sensors):
_key = modelid + "_" + sensor["uniqueid"][-5:] ###needed for uniqueness
data_dict[_key] = parse_foh(sensor)

elif modelid == "Z3-": #### Newest Model ID / Lutron Aurora / Hue Bridge treats it as two sensors, I wanted them combined
if sensor["type"] == "ZLLRelativeRotary": # Rotary Dial
_key = modelid + "_" + sensor["uniqueid"][:-5] # Rotary key is substring of button
key_value = parse_z3_rotary(sensor)
else: # sensor["type"] == "ZLLSwitch"
_key = modelid + "_" + sensor["uniqueid"]
key_value = parse_z3_switch(sensor)

##Combine parsed data
if _key in data_dict:
data_dict[_key].update(key_value)
else:
data_dict[_key] = key_value

return data_dict


Expand Down Expand Up @@ -147,6 +170,55 @@ def parse_foh(response):
return data


def parse_z3_rotary(response):
"""Parse the json response for a Lutron Aurora Rotary Event."""

Z3_DIAL = {
1: "begin",
2: "end"
}

turn = response["state"]["rotaryevent"]
dial_position = response["state"]["expectedrotation"]
if turn is None or turn not in Z3_DIAL:
dial = "No data"
else:
dial = Z3_DIAL[turn]

data = {
"model": "Z3-",
"name": response["name"],
"dial_state": dial,
"dial_position": dial_position,
"software_update": response["swupdate"]["state"],
"battery": response["config"]["battery"],
"on": response["config"]["on"],
"reachable": response["config"]["reachable"],
"last_updated": response["state"]["lastupdated"].split("T"),
}
return data

def parse_z3_switch(response):
"""Parse the json response for a Lutron Aurora."""

Z3_BUTTON = {
1000: "initial_press",
1001: "repeat",
1002: "short_release",
1003: "long_release"
}

press = response["state"]["buttonevent"]
if press is None or press not in Z3_BUTTON:
button = "No data"
else:
button = Z3_BUTTON[press]

data = {
"state": button
}
return data

def get_bridges(hass):
from homeassistant.components import hue
from homeassistant.components.hue.bridge import HueBridge
Expand Down

0 comments on commit 44db87f

Please sign in to comment.