Skip to content

Commit

Permalink
Add start of hue tap dial, fix mqtt sensor if len if more then 0, add…
Browse files Browse the repository at this point in the history
… versioncheck on startup (#1009)

* fix typo

* fix connection error because of api version

* RDM002

* rdm002

* update mqtt sensor
  • Loading branch information
hendriksen-mark authored Mar 20, 2024
1 parent 28fec9b commit 4ba7a27
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 15 deletions.
79 changes: 78 additions & 1 deletion BridgeEmulator/HueObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,68 @@ def getDevice(self):
"rtype": "zigbee_connectivity"
}]
result["type"] = "device"
elif self.modelid == "RDM002" and self.type != "ZLLRelativeRotary":
result = {"id": self.id_v2, "id_v1": "/sensors/" + self.id_v1, "type": "device"}
result["product_data"] = {"model_id": self.modelid,
"manufacturer_name": "Signify Netherlands B.V.",
"product_name": "Hue tap dial switch",
"product_archetype": "unknown_archetype",
"certified": True,
"software_version": "2.59.25",
"hardware_platform_type": "100b-119"
}
result["metadata"] = {
"archetype": "unknown_archetype",
"name": self.name
}
result["services"] = [{
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button1')),
"rtype": "button"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button2')),
"rtype": "button"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button3')),
"rtype": "button"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button4')),
"rtype": "button"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'device_power')),
"rtype": "device_power"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'zigbee_connectivity')),
"rtype": "zigbee_connectivity"
}]
result["type"] = "device"
elif self.modelid == "RDM002" and self.type == "ZLLRelativeRotary":
result = {"id": self.id_v2, "id_v1": "/sensors/" + self.id_v1, "type": "device"}
result["product_data"] = {"model_id": self.modelid,
"manufacturer_name": "Signify Netherlands B.V.",
"product_name": "Hue tap dial switch",
"product_archetype": "unknown_archetype",
"certified": True,
"software_version": "2.59.25",
"hardware_platform_type": "100b-119"
}
result["metadata"] = {
"archetype": "unknown_archetype",
"name": self.name
}
result["services"] = [{
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button3')),
"rtype": "button"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button4')),
"rtype": "button"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'device_power')),
"rtype": "device_power"
}, {
"rid": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'zigbee_connectivity')),
"rtype": "zigbee_connectivity"
}]
result["type"] = "device"
return result

def getMotion(self):
Expand Down Expand Up @@ -1910,9 +1972,10 @@ def getZigBee(self):
result["mac_address"] = self.uniqueid[:23]
result["status"] = "connected"
return result

def getButtons(self):
result = []
if self.modelid == "RWL022" or self.modelid == "RWL021" or self.modelid == "RWL020":
if self.modelid == "RWL022" or self.modelid == "RWL021" or self.modelid == "RWL020" or self.modelid == "RDM002" and self.type != "ZLLRelativeRotary":
for button in range(4):
result.append({
"id": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'button' + str(button + 1))),
Expand All @@ -1927,6 +1990,20 @@ def getButtons(self):
"type": "button"
})
return result

def getRotary(self):
result = []
if self.modelid == "RDM002" and self.type == "ZLLRelativeRotary":
result.append({
"id": str(uuid.uuid5(uuid.NAMESPACE_URL, self.id_v2 + 'relative_rotary')),
"id_v1": "/sensors/" + self.id_v1,
"owner": {
"rid": self.id_v2,
"rtype": "device"
},
"type": "relative_rotary"
})
return result

def getDevicePower(self):
result = None
Expand Down
4 changes: 2 additions & 2 deletions BridgeEmulator/configManager/configHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def load_config(self):
if int(config["swversion"]) < 1958077010:
config["swversion"] = "1962154010"
if float(config["apiversion"][:3]) < 1.56:
config["apiversion"] = "1.62_SR4"
config["apiversion"] = "1.62.0"

self.yaml_config["config"] = config
else:
Expand All @@ -105,7 +105,7 @@ def load_config(self):
"alarm":{"enabled": False,"lasttriggered": 0},
"port":{"enabled": False,"ports": [80]},
"apiUsers":{},
"apiversion":"1.62_SR4",
"apiversion":"1.62.0",
"name":"DiyHue Bridge",
"netmask":"255.255.255.0",
"swversion":"1962154010",
Expand Down
13 changes: 12 additions & 1 deletion BridgeEmulator/flaskUI/espDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask_restful import Resource
from flask import request
from functions.rules import rulesProcessor
from sensors.discover import addHueMotionSensor, addHueSwitch
from sensors.discover import addHueMotionSensor, addHueSwitch, addHueRotarySwitch
from datetime import datetime
from threading import Thread
from time import sleep
Expand Down Expand Up @@ -49,6 +49,9 @@ def get(self):
sensor = addHueMotionSensor("Hue Motion Sensor", "native", {
"mac": mac, "threaded": False})
return {"success": "device registered"}
elif args["devicetype"] == "ZLLRelativeRotary":
sensor = addHueRotarySwitch({"mac": mac})
return {"success": "device registered"}
else:
return {"fail": "unknown device"}
else:
Expand Down Expand Up @@ -92,6 +95,14 @@ def get(self):
obj.dxState["buttonevent"] = current_time
if "battery" in args:
obj.config["battery"] = int(args["battery"])
elif obj.type == "ZLLRelativeRotary":
if "rotary" in args:
obj.state["rotaryevent"] = int(args["rotary"])
obj.state["expectedrotation"] = int(args["rotation"])
obj.state["expectedeventduration"] = int(args["duration"])
obj.dxState["rotaryevent"] = current_time
if "battery" in args:
obj.config["battery"] = int(args["battery"])
else:
result = {"fail": "unknown device"}
obj.dxState["lastupdated"] = current_time
Expand Down
11 changes: 11 additions & 0 deletions BridgeEmulator/flaskUI/v2restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def get(self):
power = sensor.getDevicePower()
if power != None:
data.append(power)
for key, sensor in bridgeConfig["sensors"].items():
rotarys = sensor.getRotary()
if len(rotarys) != 0:
for rotary in rotarys:
data.append(rotary)

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

Expand Down Expand Up @@ -364,6 +369,12 @@ def get(self, resource):
if len(buttons) != 0:
for button in buttons:
response["data"].append(button)
elif resource == "relative_rotary":
for key, sensor in bridgeConfig["sensors"].items():
rotarys = sensor.getRotary()
if len(rotarys) != 0:
for rotary in rotarys:
response["data"].append(rotary)
else:
response["errors"].append({"description": "Not Found"})
del response["data"]
Expand Down
2 changes: 1 addition & 1 deletion BridgeEmulator/functions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def staticConfig():
},
"checkforupdate": False,
"lastchange": "2020-12-13T10:30:15",
"state": "unknown"
"state": "noupdates"
},
"zigbeechannel": 25
}
Expand Down
11 changes: 11 additions & 0 deletions BridgeEmulator/sensors/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ def addHueSwitch(uniqueid, sensorsType):
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}
bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(deviceData)
return(bridgeConfig["sensors"][new_sensor_id])

def addHueRotarySwitch(protocol_cfg):
uniqueid = generate_unique_id()
button_id = nextFreeId(bridgeConfig, "sensors")
button = {"name": "Hue tap dial switch", "id_v1": button_id, "modelid": "RDM002", "type": "ZLLSwitch", "protocol_cfg": protocol_cfg, "uniqueid": uniqueid + "-02-0406"}
bridgeConfig["sensors"][button_id] = HueObjects.Sensor(button)

rotary_id = nextFreeId(bridgeConfig, "sensors")
rotary = {"name": "Hue tap dial switch", "id_v1": rotary_id, "modelid": "RDM002", "type": "ZLLRelativeRotary", "protocol_cfg": protocol_cfg, "uniqueid": uniqueid + "-02-0406"}
bridgeConfig["sensors"][rotary_id] = HueObjects.Sensor(rotary)
return
11 changes: 6 additions & 5 deletions BridgeEmulator/sensors/sensor_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
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"}}}
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"}}}
# Fix Deconz types
sensorTypes["RWL020"]["ZHASwitch"] = sensorTypes["RWL020"]["ZLLSwitch"]
sensorTypes["RWL022"]["ZHASwitch"] = sensorTypes["RWL022"]["ZLLSwitch"]
sensorTypes["SML001"]["ZHATemperature"] = sensorTypes["SML001"]["ZLLTemperature"]
sensorTypes["SML001"]["ZHAPresence"] = sensorTypes["SML001"]["ZLLPresence"]
sensorTypes["SML001"]["ZHALightLevel"] = sensorTypes["SML001"]["ZLLLightLevel"]
# not used anymore?
#sensorTypes["RWL020"]["ZHASwitch"] = sensorTypes["RWL020"]["ZLLSwitch"]
#sensorTypes["RWL022"]["ZHASwitch"] = sensorTypes["RWL022"]["ZLLSwitch"]
#sensorTypes["SML001"]["ZHATemperature"] = sensorTypes["SML001"]["ZLLTemperature"]
#sensorTypes["SML001"]["ZHAPresence"] = sensorTypes["SML001"]["ZLLPresence"]
#sensorTypes["SML001"]["ZHALightLevel"] = sensorTypes["SML001"]["ZLLLightLevel"]
29 changes: 24 additions & 5 deletions BridgeEmulator/services/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@
"dial_rotate_right_fast": {"rotaryevent": 2},
}
},
"PTM 215Z": {
"dataConversion": {
"rootKey": "action",
"press_1": {"buttonevent": 1000},
"release_1": {"buttonevent": 1002},
"press_2": {"buttonevent": 2000},
"release_2": {"buttonevent": 2002},
"press_3": {"buttonevent": 3000},
"release_3": {"buttonevent": 3002},
"press_4": {"buttonevent": 4000},
"release_4": {"buttonevent": 4002},
"press_1_and_3": {"buttonevent": 1010},
"release_1_and_3": {"buttonevent": 1003},
"press_2_and_4": {"buttonevent": 2010},
"release_2_and_4": {"buttonevent": 2003},
"press_energy_bar": {"buttonevent": 5000},
}
},
}


Expand Down Expand Up @@ -283,11 +301,12 @@ def on_message(client, userdata, msg):
if getObject(key["friendly_name"]) == False: ## Add the new sensor
logging.info("MQTT: Add new mqtt sensor " + key["friendly_name"])
if key["model_id"] in standardSensors:
new_sensor_id = nextFreeId(bridgeConfig, "sensors")
sensor_type = list(sensorTypes[key["model_id"]].keys())[0]
uniqueid = convertHexToMac(key["ieee_address"]) + "-01-1000"
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}
bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(sensorData)
for sensor in sensorTypes[key["model_id"]].keys():
new_sensor_id = nextFreeId(bridgeConfig, "sensors")
sensor_type = sensorTypes[key["model_id"]][sensor]
uniqueid = convertHexToMac(key["ieee_address"]) + "-01-1000"
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}
bridgeConfig["sensors"][new_sensor_id] = HueObjects.Sensor(sensorData)
### TRADFRI Motion Sensor, Xiaomi motion sensor, etc
elif key["model_id"] in motionSensors:
logging.info("MQTT: add new motion sensor " + key["model_id"])
Expand Down
1 change: 1 addition & 0 deletions BridgeEmulator/services/updateManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ def startupCheck():
bridgeConfig["config"]["swupdate2"]["install"] = False
bridgeConfig["config"]["swupdate2"]["lastchange"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
bridgeConfig["config"]["swupdate2"]["bridge"]["lastinstall"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
versionCheck()
githubCheck()

0 comments on commit 4ba7a27

Please sign in to comment.