Turn on/off + shutdown/restart (HomeAssistantSkill)
This commit is contained in:
parent
4201b5cbcc
commit
e8af85e0d5
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -0,0 +1 @@
|
||||
(redémarre|relance) (homeassistant|home assistant)
|
@ -0,0 +1 @@
|
||||
(arrête|coupe|éteint|éteins) (homeassistant|home assistant)
|
@ -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}|)
|
||||
tu peux (éteindre|arrête) l'{entity} ((dans|à|au) {location}|)
|
||||
(arrête|éteins|éteint) (la|le|les) {entity}
|
@ -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}|)
|
||||
(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}|)
|
Reference in New Issue
Block a user