2021-09-12 21:50:30 +02:00
|
|
|
from jarvis.skills import Skill, SkillRegistering
|
|
|
|
from jarvis.skills.decorators import intent_file_handler
|
|
|
|
from jarvis.skills.productivity.homeassistant import homeassistant_client
|
|
|
|
|
|
|
|
|
|
|
|
class HomeAssistantSkill(Skill, metaclass=SkillRegistering):
|
|
|
|
def __init__(self, data=dict):
|
2021-09-13 22:09:08 +02:00
|
|
|
super().__init__("HomeAssistantSkill", data,
|
|
|
|
required_config=['HOMEASSISTANT_API_TOKEN', 'HOMEASSISTANT_API_URL'])
|
|
|
|
|
|
|
|
def on_load(self):
|
2021-09-12 21:50:30 +02:00
|
|
|
homeassistant_client.init()
|
|
|
|
|
2021-09-13 22:09:08 +02:00
|
|
|
@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()
|
|
|
|
|
2021-09-12 21:50:30 +02:00
|
|
|
@intent_file_handler("homeassistant_turn_on.intent", "HATurnOn")
|
|
|
|
def handle_turn_on(self, data):
|
2021-09-13 22:09:08 +02:00
|
|
|
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'))
|
2021-09-12 21:50:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_skill(data):
|
|
|
|
return HomeAssistantSkill(data)
|