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 #175 from robmarkcole/revert_4_click
Browse files Browse the repository at this point in the history
Reinstate 4_click and 4_hold
  • Loading branch information
robmarkcole authored Jan 27, 2020
2 parents 9ee11f3 + 754f558 commit b84b8d8
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions custom_components/huesensor/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
Entity,
ToggleEntity,
)
from homeassistant.const import (
STATE_OFF,
)
from homeassistant.const import STATE_OFF

from homeassistant.helpers.event import async_track_time_interval

Expand All @@ -33,7 +31,7 @@
TYPE_GEOFENCE = "Geofence"
ICONS = {
"RWL": "mdi:remote",
"ROM": "mdi:remote",
"ROM": "mdi:remote",
"ZGP": "mdi:remote",
"FOH": "mdi:light-switch",
"Z3-": "mdi:light-switch",
Expand All @@ -44,16 +42,18 @@
"ROM": ["last_updated", "battery", "on", "reachable"],
"ZGP": ["last_updated"],
"FOH": ["last_updated"],
"Z3-": ["last_updated",
"battery",
"on",
"reachable",
"dial_state",
"dial_position",
"software_update",
"Z3-": [
"last_updated",
"battery",
"on",
"reachable",
"dial_state",
"dial_position",
"software_update",
],
}


def parse_hue_api_response(sensors):
"""Take in the Hue API json response."""
data_dict = {} # The list of sensors, referenced by their hue_id.
Expand All @@ -73,20 +73,24 @@ def parse_hue_api_response(sensors):
elif modelid == "ZGP":
data_dict[_key] = parse_zgp(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"
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:
if _key in data_dict:
data_dict[_key].update(key_value)
else:
data_dict[_key] = key_value

return data_dict


Expand Down Expand Up @@ -169,18 +173,15 @@ def parse_foh(response):
def parse_z3_rotary(response):
"""Parse the json response for a Lutron Aurora Rotary Event."""

Z3_DIAL = {
1: "begin",
2: "end"
}
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"],
Expand All @@ -194,14 +195,15 @@ def parse_z3_rotary(response):
}
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"
1003: "long_release",
}

press = response["state"]["buttonevent"]
Expand All @@ -210,11 +212,10 @@ def parse_z3_switch(response):
else:
button = Z3_BUTTON[press]

data = {
"state": button
}
data = {"state": button}
return data


def get_bridges(hass):
from homeassistant.components import hue
from homeassistant.components.hue.bridge import HueBridge
Expand Down Expand Up @@ -342,15 +343,7 @@ def unique_id(self):
def state(self):
"""Return the state of the sensor."""
data = self._data.get(self._hue_id)
if data:
modelid = data["model"];

if modelid in ["RWL", "ROM"]:
button = data["state"][0];
if button == "4":
return STATE_OFF

return data["state"]
return data["state"]

@property
def icon(self):
Expand Down

0 comments on commit b84b8d8

Please sign in to comment.