Last active
November 19, 2016 21:06
-
-
Save dsully/a78f8c1e6d356ddb0111c8f712a82f28 to your computer and use it in GitHub Desktop.
Generate JSON config suitable for use with homebridge-radiora
This file contains hidden or 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 | |
""" | |
Generate JSON config suitable for use with homebridge-radiora: | |
https://github.com/djMax/homebridge-radiora/ | |
Copyright 2016 Dan Sully | |
MIT Licensed. | |
""" | |
import json | |
import re | |
import sys | |
import uuid | |
import lxml.etree | |
def main(): | |
if len(sys.argv) != 2: | |
sys.exit("Usage: {0} <radiora.xml>".format(sys.argv[0])) | |
tree = lxml.etree.parse(sys.argv[1]) | |
root = tree.getroot() | |
lights = dict() | |
for area in root.iterfind('.//Area'): | |
# Specific for dsully. Ignore otherwise. | |
room = area.attrib.get('Name').replace('Garage A', 'Garage') | |
# Skip the root / house. | |
if int(area.attrib.get('IntegrationID')) == 0: | |
continue | |
for output in area.iterfind('.//Output'): | |
if output.attrib.get('OutputType') in ('AUTO_DETECT', 'INC', 'NON_DIM'): | |
light = output.attrib.get('Name') | |
light = re.sub('L\d\d? ', '', light) | |
# Remove redundancy. | |
if light.startswith(room): | |
light = re.sub('{0} '.format(room), '', light) | |
iid = int(output.attrib.get('IntegrationID')) | |
lights[iid] = { | |
'name': '{0}: {1}'.format(room, light), | |
'id': iid, | |
'serial': str(uuid.uuid4()), | |
} | |
config = { | |
'lights': [], | |
'shades': [], | |
} | |
for iid in sorted(lights.keys()): | |
config['lights'].append(lights[iid]) | |
print(json.dumps(config, indent=2)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment