Rule creation for IR remotes

This commit is contained in:
Martin Bauer
2019-12-22 19:21:12 +01:00
parent bf0a15bf5f
commit 08c18b3dee
7 changed files with 400 additions and 23 deletions

View File

@@ -3,6 +3,7 @@ import argparse
from util import DeviceInfo, add_to_group, name_to_id
from ruamel.yaml import YAML
import knx_conf as knx
from ir_automations import create_rules as create_automation_rules
script_path = os.path.dirname(os.path.realpath(__file__))
yaml = YAML()
@@ -48,10 +49,14 @@ def add_knx_devices(devices, groups):
DeviceInfo("LichtWaschküche", "Waschküche Licht", 'hallway'),
# Normal lights
DeviceInfo('AussenleuchteHaustüren', 'Haustür Licht', 'outside'),
DeviceInfo('AussenleuchteObenNW', 'Haustür Licht NW', 'outside'),
DeviceInfo('AussenleuchteObenNW', 'Haustür Licht NW', 'first_floor'),
DeviceInfo('TreppenhausLicht', "Treppenhaus Licht", 'first_floor'),
DeviceInfo('WCLicht', "WC Licht", 'other'),
DeviceInfo('LampeVorratsraum', "Vorratsraum Licht", 'other'),
# Bewegungsmelder LEDs
DeviceInfo("BewegungsmelderMitte LED", "Bewegungsmelder Mitte LED", 'hallway'),
DeviceInfo("BewegungsmelderWest LED", "Bewegungsmelder West LED", 'hallway'),
DeviceInfo("BewegungsmelderOst LED", "Bewegungsmelder Ost LED", 'hallway'),
]
shutters = [
@@ -66,10 +71,6 @@ def add_knx_devices(devices, groups):
DeviceInfo("KlingelOben", "Klingel Oben", 'first_floor'),
DeviceInfo("Klingel Innen", "Klingel Innentür", 'other'),
DeviceInfo("Klingel Aussen", "Klingen Außentür", 'other'),
# Bewegungsmelder LEDs
DeviceInfo("BewegungsmelderMitte LED", "Bewegungsmelder Mitte LED", 'hallway'),
DeviceInfo("BewegungsmelderWest LED", "Bewegungsmelder West LED", 'hallway'),
DeviceInfo("BewegungsmelderOst LED", "Bewegungsmelder Ost LED", 'hallway'),
]
scene_button_names = ['ObenLinks', 'ObenRechts', 'MitteLinks', 'MitteRechts', 'UntenLinks', 'UntenRechts']
scene_button_names = [(i, e) for i, e in enumerate(scene_button_names)]
@@ -174,15 +175,33 @@ def add_fhem_devices(devices, groups):
devices[device_type].append(device)
def add_light_groups(groups):
light_groups = {
f"light_{group_id}": {
'name': content['name'] + " Lichter",
'entities': [e for e in content['entities'] if e.startswith('light.')],
}
for group_id, content in groups.items() if 'name' in content
def add_meta_groups(groups):
all_devices = set()
for group in groups.values():
all_devices.update(group['entities'])
first_floor = set(groups['first_floor']['entities'])
bedroom = set(groups['bedroom']['entities'])
outside = set(groups['outside']['entities'])
groups['all_downstairs'] = {
'name': 'Unten Alles',
'entities': [e for e in all_devices - first_floor]
}
groups['all_downstairs_but_outside'] = {
'name': 'Unten Alles Ausser Draussen',
'entities': [e for e in all_devices - first_floor - outside]
}
groups['all_downstairs_but_bedroom'] = {
'name': 'Unten Alles Ausser Schlafzimmer',
'entities': [e for e in all_devices - first_floor - bedroom],
}
groups['all_downstairs_but_bedroom_and_outside'] = {
'name': 'Unten Alles Ausser Schlafzimmer und Draussen',
'entities': [e for e in all_devices - first_floor - bedroom - outside],
}
groups.update(light_groups)
def make_sensor_exclude_list(all_devices, name_fragments):
@@ -256,8 +275,9 @@ def create_config(target_directory, development=False):
yaml.dump(all_devices, output)
yaml.dump(logbook_config(all_devices), output)
yaml.dump(recorder_config(all_devices), output)
output.write("automation manual: !include_dir_merge_list automations\n")
add_light_groups(group_dict)
add_meta_groups(group_dict)
with open(os.path.join(target_directory, 'groups.yaml'), 'w') as output:
output.write("# Dont' edit manually! this is generated!\n\n")
@@ -270,6 +290,8 @@ def create_config(target_directory, development=False):
additional_file = 'secrets_development.yaml' if development else 'secrets_deploy.yaml'
output.write(open(os.path.join(script_path, additional_file), 'r').read())
create_automation_rules(os.path.join(target_directory, 'automations'))
if __name__ == '__main__':
parser = argparse.ArgumentParser()