diff --git a/jarvis/skills/productivity/homeassistant/__init__.py b/jarvis/skills/productivity/homeassistant/__init__.py index 5f46a09..29ee66c 100644 --- a/jarvis/skills/productivity/homeassistant/__init__.py +++ b/jarvis/skills/productivity/homeassistant/__init__.py @@ -5,12 +5,31 @@ from jarvis.skills.productivity.homeassistant import homeassistant_client class HomeAssistantSkill(Skill, metaclass=SkillRegistering): def __init__(self, data=dict): - super().__init__("HomeAssistantSkill", data) + super().__init__("HomeAssistantSkill", data, + required_config=['HOMEASSISTANT_API_TOKEN', 'HOMEASSISTANT_API_URL']) + + def on_load(self): homeassistant_client.init() + @intent_file_handler("homeassistant_restart.intent", "HARestart") + def handle_restart_ha(self, data): + # TODO: ask for confirmation + homeassistant_client.restart_ha() + + @intent_file_handler("homeassistant_shutdown.intent", "HAShutdown") + def handle_shutdown_ha(self, data): + # TODO: ask for confirmation + homeassistant_client.restart_ha() + @intent_file_handler("homeassistant_turn_on.intent", "HATurnOn") def handle_turn_on(self, data): - print(homeassistant_client.find_switchable_entity(data['entity'])) + result = homeassistant_client.find_switchable_entity(data['entity']) + homeassistant_client.turn_on_entity(result.get('id')) + + @intent_file_handler("homeassistant_turn_off.intent", "HATurnOff") + def handle_turn_off(self, data): + result = homeassistant_client.find_switchable_entity(data['entity']) + homeassistant_client.turn_off_entity(result.get('id')) def create_skill(data): diff --git a/jarvis/skills/productivity/homeassistant/homeassistant_client.py b/jarvis/skills/productivity/homeassistant/homeassistant_client.py index bb17d20..5ad196f 100644 --- a/jarvis/skills/productivity/homeassistant/homeassistant_client.py +++ b/jarvis/skills/productivity/homeassistant/homeassistant_client.py @@ -32,6 +32,9 @@ def find_switchable_entity(entity): ] ) + if ha_entity is None: + print("Can't find entity for name : " + entity) + return ha_entity @@ -142,6 +145,22 @@ def get_entity_with_overridden_name(friendly_name): return None +def turn_on_entity(entity_id): + get_client().trigger_service("homeassistant", "turn_on", **{'entity_id': entity_id}) + + +def turn_off_entity(entity_id): + get_client().trigger_service("homeassistant", "turn_off", **{'entity_id': entity_id}) + + +def restart_ha(): + get_client().trigger_service("homeassistant", "restart") + + +def shutdown_ha(): + get_client().trigger_service("homeassistant", "stop") + + def init(): # init the client for the first time get_client() diff --git a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_restart.intent b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_restart.intent new file mode 100644 index 0000000..9c06478 --- /dev/null +++ b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_restart.intent @@ -0,0 +1 @@ +(redémarre|relance) (homeassistant|home assistant) \ No newline at end of file diff --git a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_shutdown.intent b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_shutdown.intent new file mode 100644 index 0000000..a52e956 --- /dev/null +++ b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_shutdown.intent @@ -0,0 +1 @@ +(arrête|coupe|éteint|éteins) (homeassistant|home assistant) \ No newline at end of file diff --git a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent index 1682f5e..37a53f0 100644 --- a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent +++ b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent @@ -1,3 +1,4 @@ -(éteint|arrête|arrêter) (voir|) {entity} ((dans|à|au) {location}|) +(éteint|éteins|arrête|arrêter) (voir|) {entity} ((dans|à|au) {location}|) tu peux (éteindre|arrête) (le|la) {entity} ((dans|à|au) {location}|) -tu peux (éteindre|arrête) l'{entity} ((dans|à|au) {location}|) \ No newline at end of file +tu peux (éteindre|arrête) l'{entity} ((dans|à|au) {location}|) +(arrête|éteins|éteint) (la|le|les) {entity} \ No newline at end of file diff --git a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent index 6766aa4..51ecae1 100644 --- a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent +++ b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent @@ -1,4 +1,5 @@ -(allume|démarre) (voir|) (la|le|) {entity} ((dans) {location}|) -(allume|démarre) (voir|) l'{entity} ((dans|à|au) {location}|) -tu peux (allumer|démarrer) (le|la|) {entity} ((dans|à|au) {location}|) -tu peux (allumer|démarrer) l'{entity} ((dans|à|au) {location}|) \ No newline at end of file +(rallume|allume|démarre) (voir|) (la|le|) {entity} ((dans) {location}|) (en {color}|) +(rallume|allume|démarre) (voir|) l'{entity} ((dans|à|au) {location}|) (en {color}|) +tu peux (rallume|allumer|démarrer) (le|la|) {entity} ((dans|à|au) {location}|) (en {color}|) +tu peux (rallume|allumer|démarrer) l'{entity} ((dans|à|au) {location}|) (en {color}|) +(rallume|allume|démarre) (la|le|les) {entity} (en {color}|) \ No newline at end of file