Skip to content

Commit 4ba7a27

Browse files
Add start of hue tap dial, fix mqtt sensor if len if more then 0, add versioncheck on startup (diyhue#1009)
* fix typo * fix connection error because of api version * RDM002 * rdm002 * update mqtt sensor
1 parent 28fec9b commit 4ba7a27

File tree

9 files changed

+146
-15
lines changed

9 files changed

+146
-15
lines changed

BridgeEmulator/HueObjects/__init__.py

+78-1
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,68 @@ def getDevice(self):
18711871
"rtype": "zigbee_connectivity"
18721872
}]
18731873
result["type"] = "device"
1874+
elif self.modelid == "RDM002" and self.type != "ZLLRelativeRotary":
1875+
result = {"id": self.id_v2, "id_v1": "/sensors/" + self.id_v1, "type": "device"}
1876+
result["product_data"] = {"model_id": self.modelid,
1877+
"manufacturer_name": "Signify Netherlands B.V.",
1878+
"product_name": "Hue tap dial switch",
1879+
"product_archetype": "unknown_archetype",
1880+
"certified": True,
1881+
"software_version": "2.59.25",
1882+
"hardware_platform_type": "100b-119"
1883+
}
1884+
result["metadata"] = {
1885+
"archetype": "unknown_archetype",
1886+
"name": self.name
1887+
}
1888+
result["services"] = [{
1889+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button1')),
1890+
"rtype": "button"
1891+
}, {
1892+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button2')),
1893+
"rtype": "button"
1894+
}, {
1895+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button3')),
1896+
"rtype": "button"
1897+
}, {
1898+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button4')),
1899+
"rtype": "button"
1900+
}, {
1901+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'device_power')),
1902+
"rtype": "device_power"
1903+
}, {
1904+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'zigbee_connectivity')),
1905+
"rtype": "zigbee_connectivity"
1906+
}]
1907+
result["type"] = "device"
1908+
elif self.modelid == "RDM002" and self.type == "ZLLRelativeRotary":
1909+
result = {"id": self.id_v2, "id_v1": "/sensors/" + self.id_v1, "type": "device"}
1910+
result["product_data"] = {"model_id": self.modelid,
1911+
"manufacturer_name": "Signify Netherlands B.V.",
1912+
"product_name": "Hue tap dial switch",
1913+
"product_archetype": "unknown_archetype",
1914+
"certified": True,
1915+
"software_version": "2.59.25",
1916+
"hardware_platform_type": "100b-119"
1917+
}
1918+
result["metadata"] = {
1919+
"archetype": "unknown_archetype",
1920+
"name": self.name
1921+
}
1922+
result["services"] = [{
1923+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button3')),
1924+
"rtype": "button"
1925+
}, {
1926+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button4')),
1927+
"rtype": "button"
1928+
}, {
1929+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'device_power')),
1930+
"rtype": "device_power"
1931+
}, {
1932+
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'zigbee_connectivity')),
1933+
"rtype": "zigbee_connectivity"
1934+
}]
1935+
result["type"] = "device"
18741936
return result
18751937

18761938
def getMotion(self):
@@ -1910,9 +1972,10 @@ def getZigBee(self):
19101972
result["mac_address"] = self.uniqueid[:23]
19111973
result["status"] = "connected"
19121974
return result
1975+
19131976
def getButtons(self):
19141977
result = []
1915-
if self.modelid == "RWL022" or self.modelid == "RWL021" or self.modelid == "RWL020":
1978+
if self.modelid == "RWL022" or self.modelid == "RWL021" or self.modelid == "RWL020" or self.modelid == "RDM002" and self.type != "ZLLRelativeRotary":
19161979
for button in range(4):
19171980
result.append({
19181981
"id": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button' + str(button + 1))),
@@ -1927,6 +1990,20 @@ def getButtons(self):
19271990
"type": "button"
19281991
})
19291992
return result
1993+
1994+
def getRotary(self):
1995+
result = []
1996+
if self.modelid == "RDM002" and self.type == "ZLLRelativeRotary":
1997+
result.append({
1998+
"id": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'relative_rotary')),
1999+
"id_v1": "/sensors/" + self.id_v1,
2000+
"owner": {
2001+
"rid": self.id_v2,
2002+
"rtype": "device"
2003+
},
2004+
"type": "relative_rotary"
2005+
})
2006+
return result
19302007

19312008
def getDevicePower(self):
19322009
result = None

BridgeEmulator/configManager/configHandler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def load_config(self):
9292
if int(config["swversion"]) < 1958077010:
9393
config["swversion"] = "1962154010"
9494
if float(config["apiversion"][:3]) < 1.56:
95-
config["apiversion"] = "1.62_SR4"
95+
config["apiversion"] = "1.62.0"
9696

9797
self.yaml_config["config"] = config
9898
else:
@@ -105,7 +105,7 @@ def load_config(self):
105105
"alarm":{"enabled": False,"lasttriggered": 0},
106106
"port":{"enabled": False,"ports": [80]},
107107
"apiUsers":{},
108-
"apiversion":"1.62_SR4",
108+
"apiversion":"1.62.0",
109109
"name":"DiyHue Bridge",
110110
"netmask":"255.255.255.0",
111111
"swversion":"1962154010",

BridgeEmulator/flaskUI/espDevices.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from flask_restful import Resource
66
from flask import request
77
from functions.rules import rulesProcessor
8-
from sensors.discover import addHueMotionSensor, addHueSwitch
8+
from sensors.discover import addHueMotionSensor, addHueSwitch, addHueRotarySwitch
99
from datetime import datetime
1010
from threading import Thread
1111
from time import sleep
@@ -49,6 +49,9 @@ def get(self):
4949
sensor = addHueMotionSensor("Hue Motion Sensor", "native", {
5050
"mac": mac, "threaded": False})
5151
return {"success": "device registered"}
52+
elif args["devicetype"] == "ZLLRelativeRotary":
53+
sensor = addHueRotarySwitch({"mac": mac})
54+
return {"success": "device registered"}
5255
else:
5356
return {"fail": "unknown device"}
5457
else:
@@ -92,6 +95,14 @@ def get(self):
9295
obj.dxState["buttonevent"] = current_time
9396
if "battery" in args:
9497
obj.config["battery"] = int(args["battery"])
98+
elif obj.type == "ZLLRelativeRotary":
99+
if "rotary" in args:
100+
obj.state["rotaryevent"] = int(args["rotary"])
101+
obj.state["expectedrotation"] = int(args["rotation"])
102+
obj.state["expectedeventduration"] = int(args["duration"])
103+
obj.dxState["rotaryevent"] = current_time
104+
if "battery" in args:
105+
obj.config["battery"] = int(args["battery"])
95106
else:
96107
result = {"fail": "unknown device"}
97108
obj.dxState["lastupdated"] = current_time

BridgeEmulator/flaskUI/v2restapi.py

+11
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ def get(self):
276276
power = sensor.getDevicePower()
277277
if power != None:
278278
data.append(power)
279+
for key, sensor in bridgeConfig["sensors"].items():
280+
rotarys = sensor.getRotary()
281+
if len(rotarys) != 0:
282+
for rotary in rotarys:
283+
data.append(rotary)
279284

280285
return {"errors": [], "data": data}
281286

@@ -364,6 +369,12 @@ def get(self, resource):
364369
if len(buttons) != 0:
365370
for button in buttons:
366371
response["data"].append(button)
372+
elif resource == "relative_rotary":
373+
for key, sensor in bridgeConfig["sensors"].items():
374+
rotarys = sensor.getRotary()
375+
if len(rotarys) != 0:
376+
for rotary in rotarys:
377+
response["data"].append(rotary)
367378
else:
368379
response["errors"].append({"description": "Not Found"})
369380
del response["data"]

BridgeEmulator/functions/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def staticConfig():
5757
},
5858
"checkforupdate": False,
5959
"lastchange": "2020-12-13T10:30:15",
60-
"state": "unknown"
60+
"state": "noupdates"
6161
},
6262
"zigbeechannel": 25
6363
}

BridgeEmulator/sensors/discover.py

+11
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ def addHueSwitch(uniqueid, sensorsType):
3838
deviceData = {"id_v1": new_sensor_id, "state": {"buttonevent": 0, "lastupdated": "none"}, "config": {"on": True, "battery": 100, "reachable": True}, "name": "Dimmer Switch" if sensorsType == "ZLLSwitch" else "Tap Switch", "type": sensorsType, "modelid": "RWL021" if sensorsType == "ZLLSwitch" else "ZGPSWITCH", "manufacturername": "Philips", "swversion": "5.45.1.17846" if sensorsType == "ZLLSwitch" else "", "uniqueid": uniqueid}
3939
bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(deviceData)
4040
return(bridgeConfig["sensors"][new_sensor_id])
41+
42+
def addHueRotarySwitch(protocol_cfg):
43+
uniqueid = generate_unique_id()
44+
button_id = nextFreeId(bridgeConfig, "sensors")
45+
button = {"name": "Hue tap dial switch", "id_v1": button_id, "modelid": "RDM002", "type": "ZLLSwitch", "protocol_cfg": protocol_cfg, "uniqueid": uniqueid + "-02-0406"}
46+
bridgeConfig["sensors"][button_id] = HueObjects.Sensor(button)
47+
48+
rotary_id = nextFreeId(bridgeConfig, "sensors")
49+
rotary = {"name": "Hue tap dial switch", "id_v1": rotary_id, "modelid": "RDM002", "type": "ZLLRelativeRotary", "protocol_cfg": protocol_cfg, "uniqueid": uniqueid + "-02-0406"}
50+
bridgeConfig["sensors"][rotary_id] = HueObjects.Sensor(rotary)
51+
return

BridgeEmulator/sensors/sensor_types.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
sensorTypes["TRADFRI on/off switch"] = {"ZHASwitch": {"state": {"buttonevent": 1002, "lastupdated": "none"}, "config": {"alert": "none", "battery": 90, "on": True, "reachable": True}, "static": {"swversion": "2.2.008", "manufacturername": "IKEA of Sweden"}}}
1616
sensorTypes["TRADFRI wireless dimmer"] = {"ZHASwitch": {"state": {"buttonevent": 1002, "lastupdated": "none"}, "config": {"alert": "none", "battery": 90, "on": True, "reachable": True}, "static": {"swversion": "1.2.248", "manufacturername": "IKEA of Sweden"}}}
1717
# Fix Deconz types
18-
sensorTypes["RWL020"]["ZHASwitch"] = sensorTypes["RWL020"]["ZLLSwitch"]
19-
sensorTypes["RWL022"]["ZHASwitch"] = sensorTypes["RWL022"]["ZLLSwitch"]
20-
sensorTypes["SML001"]["ZHATemperature"] = sensorTypes["SML001"]["ZLLTemperature"]
21-
sensorTypes["SML001"]["ZHAPresence"] = sensorTypes["SML001"]["ZLLPresence"]
22-
sensorTypes["SML001"]["ZHALightLevel"] = sensorTypes["SML001"]["ZLLLightLevel"]
18+
# not used anymore?
19+
#sensorTypes["RWL020"]["ZHASwitch"] = sensorTypes["RWL020"]["ZLLSwitch"]
20+
#sensorTypes["RWL022"]["ZHASwitch"] = sensorTypes["RWL022"]["ZLLSwitch"]
21+
#sensorTypes["SML001"]["ZHATemperature"] = sensorTypes["SML001"]["ZLLTemperature"]
22+
#sensorTypes["SML001"]["ZHAPresence"] = sensorTypes["SML001"]["ZLLPresence"]
23+
#sensorTypes["SML001"]["ZHALightLevel"] = sensorTypes["SML001"]["ZLLLightLevel"]

BridgeEmulator/services/mqtt.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,24 @@
157157
"dial_rotate_right_fast": {"rotaryevent": 2},
158158
}
159159
},
160+
"PTM 215Z": {
161+
"dataConversion": {
162+
"rootKey": "action",
163+
"press_1": {"buttonevent": 1000},
164+
"release_1": {"buttonevent": 1002},
165+
"press_2": {"buttonevent": 2000},
166+
"release_2": {"buttonevent": 2002},
167+
"press_3": {"buttonevent": 3000},
168+
"release_3": {"buttonevent": 3002},
169+
"press_4": {"buttonevent": 4000},
170+
"release_4": {"buttonevent": 4002},
171+
"press_1_and_3": {"buttonevent": 1010},
172+
"release_1_and_3": {"buttonevent": 1003},
173+
"press_2_and_4": {"buttonevent": 2010},
174+
"release_2_and_4": {"buttonevent": 2003},
175+
"press_energy_bar": {"buttonevent": 5000},
176+
}
177+
},
160178
}
161179

162180

@@ -283,11 +301,12 @@ def on_message(client, userdata, msg):
283301
if getObject(key["friendly_name"]) == False: ## Add the new sensor
284302
logging.info("MQTT: Add new mqtt sensor " + key["friendly_name"])
285303
if key["model_id"] in standardSensors:
286-
new_sensor_id = nextFreeId(bridgeConfig, "sensors")
287-
sensor_type = list(sensorTypes[key["model_id"]].keys())[0]
288-
uniqueid = convertHexToMac(key["ieee_address"]) + "-01-1000"
289-
sensorData = {"name": key["friendly_name"], "protocol": "mqtt", "modelid": key["model_id"], "type": sensor_type, "uniqueid": uniqueid,"protocol_cfg": {"friendly_name": key["friendly_name"], "ieeeAddr": key["ieee_address"], "model": key["definition"]["model"]}, "id_v1": new_sensor_id}
290-
bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(sensorData)
304+
for sensor in sensorTypes[key["model_id"]].keys():
305+
new_sensor_id = nextFreeId(bridgeConfig, "sensors")
306+
sensor_type = sensorTypes[key["model_id"]][sensor]
307+
uniqueid = convertHexToMac(key["ieee_address"]) + "-01-1000"
308+
sensorData = {"name": key["friendly_name"], "protocol": "mqtt", "modelid": key["model_id"], "type": sensor_type, "uniqueid": uniqueid,"protocol_cfg": {"friendly_name": key["friendly_name"], "ieeeAddr": key["ieee_address"], "model": key["definition"]["model"]}, "id_v1": new_sensor_id}
309+
bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(sensorData)
291310
### TRADFRI Motion Sensor, Xiaomi motion sensor, etc
292311
elif key["model_id"] in motionSensors:
293312
logging.info("MQTT: add new motion sensor " + key["model_id"])

BridgeEmulator/services/updateManager.py

+1
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ def startupCheck():
112112
bridgeConfig["config"]["swupdate2"]["install"] = False
113113
bridgeConfig["config"]["swupdate2"]["lastchange"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
114114
bridgeConfig["config"]["swupdate2"]["bridge"]["lastinstall"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
115+
versionCheck()
115116
githubCheck()

0 commit comments

Comments
 (0)