|
#!/usr/bin/env python3 |
|
|
|
import argparse |
|
import logging |
|
import os |
|
import shutil |
|
import sys |
|
from collections import OrderedDict |
|
|
|
import homeassistant.core |
|
from homeassistant.config import find_config_file, get_default_config_dir, load_yaml_config_file |
|
from homeassistant.util import yaml |
|
|
|
_LOGGER = logging.getLogger(__name__) |
|
GROUP_CONFIG = None |
|
|
|
|
|
def convert_all_group(obj_id): |
|
lovelace = OrderedDict() |
|
lookup = { |
|
'all_lights': 'light', |
|
'all_automations': 'automation', |
|
'all_devices': 'device_tracker', |
|
'all_fans': 'fan', |
|
'all_locks': 'lock', |
|
'all_covers': 'cover', |
|
'all_remotes': 'remote', |
|
'all_switches': 'switch', |
|
'all_vacuum_cleaners': 'vacuum', |
|
'all_scripts': 'script', |
|
} |
|
if obj_id not in lookup: |
|
_LOGGER.warning("Unknown group.all_* group 'group.{}'".format(obj_id)) |
|
return None |
|
lovelace['type'] = 'entity-filter' |
|
lovelace['card_config'] = {'title': obj_id.replace('_', ' ').title()} |
|
lovelace['filter'] = [{'domain': lookup[obj_id]}] |
|
return lovelace |
|
|
|
|
|
def convert_card(entity_id): |
|
domain, obj_id = entity_id.split('.') |
|
if domain == 'group': |
|
if obj_id not in GROUP_CONFIG: |
|
if obj_id.startswith('all_'): |
|
return convert_all_group(obj_id) |
|
_LOGGER.error("Couldn't find group with entity id {}".format(entity_id)) |
|
return None |
|
return convert_group(GROUP_CONFIG[obj_id], entity_id) |
|
elif domain == 'camera': |
|
return OrderedDict([ |
|
('type', 'camera-preview'), |
|
('entity', entity_id) |
|
]) |
|
elif domain == 'history_graph': |
|
return OrderedDict([ |
|
('type', 'history-graph'), |
|
('entity', entity_id) |
|
]) |
|
elif domain == 'media_player': |
|
return OrderedDict([ |
|
('type', 'media-control'), |
|
('entity', entity_id) |
|
]) |
|
elif domain == 'plant': |
|
return OrderedDict([ |
|
('type', 'plant-status'), |
|
('entity', entity_id) |
|
]) |
|
elif domain == 'weather': |
|
return OrderedDict([ |
|
('type', 'weather-forecast'), |
|
('entity', entity_id) |
|
]) |
|
_LOGGER.error("Cannot determine card type for entity id '{}'. Maybe it is unsupported?" |
|
"".format(entity_id)) |
|
return None |
|
|
|
|
|
def convert_group(config, name): |
|
if config.get('view', False): |
|
_LOGGER.error("Cannot have view group '{}' inside another group".format(name)) |
|
return None |
|
|
|
lovelace = OrderedDict() |
|
lovelace['type'] = 'entities' |
|
if 'name' in config: |
|
lovelace['title'] = config['name'] |
|
entities = lovelace['entities'] = [] |
|
extra_cards = [] |
|
for entity_id in config.get('entities', []): |
|
domain, obj_id = entity_id.split('.') |
|
if domain in ['group', 'media_player', 'camera', 'history_graph', |
|
'media_player', 'plant', 'weather']: |
|
_LOGGER.warning("Cannot have domain '{}' within a non-view group {}! " |
|
"I will put it into the parent view-type group.".format( |
|
domain, name)) |
|
card = convert_card(entity_id) |
|
if card is not None: |
|
extra_cards.append(card) |
|
continue |
|
entities.append(entity_id) |
|
return lovelace, extra_cards |
|
|
|
|
|
def convert_view(config, name): |
|
lovelace = OrderedDict() |
|
if 'name' in config: |
|
lovelace['name'] = config['name'] |
|
if 'icon' in config: |
|
lovelace['tab_icon'] = config['icon'] |
|
cards = lovelace['cards'] = [] |
|
for entity_id in config.get('entities', []): |
|
card = convert_card(entity_id) |
|
if card is None: |
|
continue |
|
if isinstance(card, tuple): |
|
cards.append(card[0]) |
|
cards.extend(card[1]) |
|
else: |
|
cards.append(card) |
|
|
|
return lovelace |
|
|
|
|
|
def main(): |
|
global GROUP_CONFIG |
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
try: |
|
from colorlog import ColoredFormatter |
|
logging.getLogger().handlers[0].setFormatter(ColoredFormatter( |
|
"%(log_color)s%(levelname)s %(message)s%(reset)s", |
|
datefmt="", |
|
reset=True, |
|
log_colors={ |
|
'DEBUG': 'cyan', |
|
'INFO': 'green', |
|
'WARNING': 'yellow', |
|
'ERROR': 'red', |
|
'CRITICAL': 'red', |
|
} |
|
)) |
|
except ImportError: |
|
pass |
|
|
|
parser = argparse.ArgumentParser( |
|
description="Check Home Assistant configuration.") |
|
parser.add_argument( |
|
'-c', '--config', |
|
default=get_default_config_dir(), |
|
help="Directory that contains the Home Assistant configuration") |
|
|
|
args = parser.parse_args() |
|
|
|
config_dir = os.path.join(os.getcwd(), args.config) |
|
|
|
hass = homeassistant.core.HomeAssistant() |
|
hass.config.config_dir = config_dir |
|
|
|
config_path = find_config_file(config_dir) |
|
config = load_yaml_config_file(config_path) |
|
GROUP_CONFIG = config['group'] |
|
name = config['homeassistant'].get('name', 'Home') |
|
lovelace = OrderedDict() |
|
lovelace['name'] = name |
|
views = lovelace['views'] = [] |
|
|
|
if 'default_view' in GROUP_CONFIG: |
|
views.append(convert_view(GROUP_CONFIG['default_view'], 'default_view')) |
|
|
|
for name, conf in GROUP_CONFIG.items(): |
|
if name == 'default_view': |
|
continue |
|
if not conf.get('view', False): |
|
continue |
|
views.append(convert_view(conf, name)) |
|
|
|
views.append({ |
|
'name': "All Entities", |
|
'tab_icon': "mdi:settings", |
|
'cards': [{ |
|
'type': 'entity-filter', |
|
'filter': [{}], |
|
'card_config': { |
|
'title': 'All Entities' |
|
} |
|
}], |
|
}) |
|
|
|
lovelace_path = os.path.join(config_dir, 'ui-lovelace.yaml') |
|
if os.path.exists(lovelace_path): |
|
i = 0 |
|
while os.path.exists(lovelace_path + '.bkp.{}'.format(i)): |
|
i += 1 |
|
bkp_path = lovelace_path + '.bkp.{}'.format(i) |
|
shutil.move(lovelace_path, bkp_path) |
|
_LOGGER.error("The lovelace configuration already exists under %s! " |
|
"I will move it to %s", lovelace_path, bkp_path) |
|
with open(lovelace_path, 'w', encoding='utf-8') as f: |
|
f.write(yaml.dump(lovelace) + '\n') |
|
_LOGGER.info("Successfully migrated lovelace configuration to %s", lovelace_path) |
|
return 0 |
|
|
|
|
|
if __name__ == '__main__': |
|
sys.exit(main()) |
I have hassbian and i also tried with virtualenv activated, but i got the same error....
Edit: i got the script running but with a lot of errors...:
python3 lovelace_migrate.py -c /home/homeassistant/.homeassistant/
ERROR Cannot determine card type for entity id 'binary_sensor.mosquitto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'binary_sensor.zanzito_s8_status'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'binary_sensor.zanzito_note_3_status'. Maybe it is unsupported?
ERROR Couldn't find group with entity id group.bagno
ERROR Couldn't find group with entity id group.balcone
ERROR Couldn't find group with entity id group.radio
ERROR Couldn't find group with entity id group.input
WARNING Cannot have domain 'camera' within a non-view group group.location! I will put it into the parent view-type group.
WARNING Cannot have domain 'camera' within a non-view group group.location! I will put it into the parent view-type group.
ERROR Couldn't find group with entity id group.speed_test
ERROR Couldn't find group with entity id group.homeassistant
ERROR Couldn't find group with entity id group.presenze
ERROR Couldn't find group with entity id group.sensori
ERROR Couldn't find group with entity id group.tado
ERROR Couldn't find group with entity id group.maintenance
ERROR Cannot determine card type for entity id 'input_boolean.mauhome'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.sun_based_theme'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.day_of_week'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.time'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.nextsunrise'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.nextsunset'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.season'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'updater.updater'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.temperature_158d0002009a82'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.humidity_158d0002009a82'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.illumination_7811dcb25b7c'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ciabatta_salotto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ciabatta_2'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.plug_158d0001f55131'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.strip_led'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.candle_light'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'input_boolean.tv_power_status'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.tvpower'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.n30_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.n30_radio'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.sky'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.audio_video_1'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.audio_video_2'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.sky'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.audio_cast_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.audio_cast_off'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv_samsung_cast'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv_samsung_kodi'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv_samsung_sky'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_led_strip'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_luci_al_tramonto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.movimento_al_buio_accendi_luci_salotto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_radio_mattina'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_salotto_mattina'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.click_pulsante_1_accendi_luce_salotto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.doppio_click_pulsante_1_spegni_luce_salotto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.samsung_tv_power_status_to_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.samsung_tv_power_status_to_off'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.plafoniera_studio'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.philips_3'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.philips_5'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'binary_sensor.switch_158d00019cd3cd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.illumination_158d0001ddac9e'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.luci_studio_notte'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.spegni_luce_studio'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'binary_sensor.door_window_sensor_158d000201b557'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.yeelight_strip_1'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.yeelight_strip_2'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_luci_quando_apri_porta'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.yeelight_3'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.yeelight_4'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.plug_158d0001f551eb'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.temperature_158d0001b95fa0'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.humidity_158d0001b95fa0'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.pressure_158d0001b95fa0'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_luce_camera_letto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.accendi_presa_camera_letto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.click_pulsante_2_accendi_luci_camera_letto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.doppio_click_pulsante_2_spegni_luci_camera_letto'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.tv_lg'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.volume_up'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.volume_down'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.source'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.right'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.left'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.canale_piu'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.canale_meno'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cast_lg_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cast_lg_off'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cine_sony'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.italia_1_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.la_7'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.marco_polo'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_1_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_2_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_3_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rete_4_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.canale_5_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_sport'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.food_network'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.paramount'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cielo'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_premium'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_movie'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_4'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_5'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.iris'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.mediaset_20'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv8'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv9'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.sportitalia'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.focus'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.mediaset_extra'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'binary_sensor.motion_sensor_158d0002006e75'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'sensor.illumination_158d0002006e75'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'light.bedside_wifi'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.plug_158d0002115042'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.strip_led'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'automation.notifica_luce_pioggia'. Maybe it is unsupported?
ERROR Couldn't find group with entity id group.stato_media_player
ERROR Cannot determine card type for entity id 'switch.tvpower'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.n30_radio'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.n30_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_vol_down'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_vol_up'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_video1'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_video2'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.ampli_cd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.n30_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.n30_radio'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.audio_cast_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.audio_cast_off'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.radio_start'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.radio_stop'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv_samsung_cast'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv_samsung_kodi'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv_samsung_sky'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.canale_meno'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.canale_piu'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.left'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.right'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.source'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.tv_lg'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.volume_down'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'switch.volume_up'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cast_lg_off'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cast_lg_on'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cine_sony'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.italia_1_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.la_7'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.marco_polo'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_1_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_2_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_3_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rete_4_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.canale_5_hd'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_sport'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.food_network'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.paramount'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.cielo'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_premium'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_movie'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_4'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.rai_5'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.iris'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.mediaset_20'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv8'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.tv9'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.sportitalia'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.focus'. Maybe it is unsupported?
ERROR Cannot determine card type for entity id 'script.mediaset_extra'. Maybe it is unsupported?
ERROR Couldn't find group with entity id group.scene
ERROR Couldn't find group with entity id group.previsioni_meteo
WARNING Cannot have domain 'camera' within a non-view group group.camere! I will put it into the parent view-type group.
WARNING Cannot have domain 'camera' within a non-view group group.camere! I will put it into the parent view-type group.
ERROR Couldn't find group with entity id group.meteo_darksky
ERROR Couldn't find group with entity id group.previsioni_darksky
ERROR Couldn't find group with entity id group.previsioni_meteo_owm
Traceback (most recent call last):
File "lovelace_migrate.py", line 208, in
sys.exit(main())
File "lovelace_migrate.py", line 176, in main
if not conf.get('view', False):
AttributeError: 'NodeListClass' object has no attribute 'get'