Created
March 11, 2021 23:38
-
-
Save doctorjames/61e774940d869d669f3d3445a3debec0 to your computer and use it in GitHub Desktop.
Add missing keys to deconz device configs (https://github.com/diyhue/diyHue/issues/594)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import json | |
templates = [ | |
{ | |
"capabilities": { | |
"certified": True, | |
"inputs": [ | |
{ | |
"events": [{"buttonevent": 34, "eventtype": "initial_press"}], | |
"repeatintervals": [], | |
}, | |
{ | |
"events": [{"buttonevent": 16, "eventtype": "initial_press"}], | |
"repeatintervals": [], | |
}, | |
{ | |
"events": [{"buttonevent": 17, "eventtype": "initial_press"}], | |
"repeatintervals": [], | |
}, | |
{ | |
"events": [{"buttonevent": 18, "eventtype": "initial_press"}], | |
"repeatintervals": [], | |
}, | |
], | |
"primary": True, | |
}, | |
"config": {"on": True}, | |
"diversityid": "d8cde5d5-0eef-4b95-b0f0-71ddd2952af4", | |
"manufacturername": "Signify Netherlands B.V.", | |
"modelid": "ZGPSWITCH", | |
"productname": "Hue tap switch", | |
"state": {"buttonevent": 17, "lastupdated": "2021-03-11T02:15:17"}, | |
"swupdate": {"lastinstall": None, "state": "notupdatable"}, | |
"type": "ZGPSwitch", | |
}, | |
{ | |
"capabilities": { | |
"certified": True, | |
"inputs": [ | |
{ | |
"events": [ | |
{"buttonevent": 1000, "eventtype": "initial_press"}, | |
{"buttonevent": 1001, "eventtype": "repeat"}, | |
{"buttonevent": 1002, "eventtype": "short_release"}, | |
{"buttonevent": 1003, "eventtype": "long_release"}, | |
], | |
"repeatintervals": [800], | |
}, | |
{ | |
"events": [ | |
{"buttonevent": 2000, "eventtype": "initial_press"}, | |
{"buttonevent": 2001, "eventtype": "repeat"}, | |
{"buttonevent": 2002, "eventtype": "short_release"}, | |
{"buttonevent": 2003, "eventtype": "long_release"}, | |
], | |
"repeatintervals": [800], | |
}, | |
{ | |
"events": [ | |
{"buttonevent": 3000, "eventtype": "initial_press"}, | |
{"buttonevent": 3001, "eventtype": "repeat"}, | |
{"buttonevent": 3002, "eventtype": "short_release"}, | |
{"buttonevent": 3003, "eventtype": "long_release"}, | |
], | |
"repeatintervals": [800], | |
}, | |
{ | |
"events": [ | |
{"buttonevent": 4000, "eventtype": "initial_press"}, | |
{"buttonevent": 4001, "eventtype": "repeat"}, | |
{"buttonevent": 4002, "eventtype": "short_release"}, | |
{"buttonevent": 4003, "eventtype": "long_release"}, | |
], | |
"repeatintervals": [800], | |
}, | |
], | |
"primary": True, | |
}, | |
"config": {"battery": 100, "on": True, "reachable": True}, | |
"diversityid": "73bbabea-3420-499a-9856-46bf437e119b", | |
"manufacturername": "Signify Netherlands B.V.", | |
"modelid": "RWL021", | |
"productname": "Hue dimmer switch", | |
"state": {"buttonevent": 1002, "lastupdated": "2021-03-10T23:52:29"}, | |
"swupdate": {"lastinstall": "2020-10-03T10:39:43", "state": "noupdates"}, | |
"swversion": "6.1.1.28573", | |
"type": "ZLLSwitch", | |
"uniqueid": "00:17:88:01:08:73:73:0a-02-fc00", | |
}, | |
] | |
def augment_sensor_definition(sensor): | |
"""Search templates for matching sensor and add any missing keys""" | |
if not "type" in sensor or not "modelid" in sensor: | |
return | |
for template in templates: | |
if ( | |
sensor["type"] == template["type"] | |
and sensor["modelid"] == template["modelid"] | |
): | |
for key, value in template.items(): | |
# only update sensor if key does not exist | |
sensor.setdefault(key, value) | |
return | |
def main(): | |
with open("config.json") as config_file: | |
config = json.load(config_file) | |
for sensor in config.get("sensors", {}).values(): | |
augment_sensor_definition(sensor) | |
with open("config.json.new", "w") as config_file: | |
json.dump(config, config_file, indent=4) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment