Big restructuring - repo is now a full home assistant config directory
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import os
|
||||
from util import DeviceInfo, add_to_group
|
||||
from ruamel.yaml import YAML
|
||||
import knx_conf as knx
|
||||
|
||||
|
||||
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||
yaml = YAML()
|
||||
|
||||
|
||||
@@ -74,8 +75,8 @@ def add_knx_devices(devices, groups):
|
||||
DeviceInfo("WohnzimmerSteckdose2", "Wohnzimmer Steckdose 2", 'living_area'),
|
||||
]
|
||||
|
||||
imported_csv = knx.import_ets5_csv_file('knx_data/export_project1.csv')
|
||||
imported_csv.update(knx.import_ets5_csv_file('knx_data/export_project2.csv'))
|
||||
imported_csv = knx.import_ets5_csv_file(os.path.join(script_path, 'knx_data/export_project1.csv'))
|
||||
imported_csv.update(knx.import_ets5_csv_file(os.path.join(script_path, 'knx_data/export_project2.csv')))
|
||||
|
||||
knx.extent(devices, knx.create_lights(lights, imported_csv))
|
||||
knx.extent(devices, knx.create_shutters(shutters, imported_csv))
|
||||
@@ -88,7 +89,8 @@ def add_knx_devices(devices, groups):
|
||||
|
||||
|
||||
def add_fhem_devices(devices, groups):
|
||||
fhem_yaml = yaml.load(open('fhem.yaml'))
|
||||
fhem_yaml_path = os.path.join(script_path, 'fhem.yaml')
|
||||
fhem_yaml = yaml.load(open(fhem_yaml_path))
|
||||
for device_type, device_list in fhem_yaml.items():
|
||||
if device_type not in devices:
|
||||
devices[device_type] = []
|
||||
@@ -111,19 +113,25 @@ def add_light_groups(groups):
|
||||
groups.update(light_groups)
|
||||
|
||||
|
||||
def main():
|
||||
group_dict = yaml.load(open('groups.yaml'))
|
||||
def create_config(target_directory):
|
||||
groups_yaml_path = os.path.join(script_path, 'groups.yaml')
|
||||
manual_config_path = os.path.join(script_path, 'manual_config.yaml')
|
||||
group_dict = yaml.load(open(groups_yaml_path))
|
||||
|
||||
all_devices = {}
|
||||
add_knx_devices(all_devices, group_dict)
|
||||
add_fhem_devices(all_devices, group_dict)
|
||||
|
||||
with open('output/configuration.yaml', 'w') as output:
|
||||
output.write(open('manual_config.yaml', 'r').read())
|
||||
with open(os.path.join(target_directory, 'configuration.yaml'), 'w') as output:
|
||||
output.write("# Dont' edit manually! this is generated!\n\n")
|
||||
output.write(open(manual_config_path, 'r').read())
|
||||
yaml.dump(all_devices, output)
|
||||
add_light_groups(group_dict)
|
||||
yaml.dump(group_dict, open('output/groups.yaml', 'w'))
|
||||
|
||||
with open(os.path.join(target_directory, 'groups.yaml'), 'w') as output:
|
||||
output.write("# Dont' edit manually! this is generated!\n\n")
|
||||
yaml.dump(group_dict, output)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
create_config(target_directory=os.getcwd())
|
||||
|
||||
Reference in New Issue
Block a user