-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/rgb lights #69
base: 20.08
Are you sure you want to change the base?
Changes from 12 commits
03adeaf
db3de74
f260e50
a465f2b
6717585
2c75b29
4b82878
7993872
30ecd6a
218727d
b433213
01e9fbe
f383999
12b562e
a86d5c6
715bc81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,12 @@ def _setup(self, force=False): | |
# Check if user filled IP, port and Token in configuration | ||
if not ip: | ||
self.speak_dialog('homeassistant.error.setup', data={ | ||
"field": "I.P."}) | ||
"field": "I.P."}) | ||
return | ||
|
||
if not token: | ||
self.speak_dialog('homeassistant.error.setup', data={ | ||
"field": "token"}) | ||
"field": "token"}) | ||
return | ||
|
||
portnumber = self.settings.get('portnum') | ||
|
@@ -54,7 +54,7 @@ def _setup(self, force=False): | |
except ValueError: | ||
# String might be some rubbish (like '') | ||
self.speak_dialog('homeassistant.error.setup', data={ | ||
"field": "port"}) | ||
"field": "port"}) | ||
return | ||
|
||
self.ha = HomeAssistantClient( | ||
|
@@ -120,7 +120,7 @@ def _check_availability(self, ha_entity): | |
""" Check if state is `unavailable`, if yes, inform user about it. """ | ||
|
||
self.speak_dialog('homeassistant.device.unavailable', data={ | ||
"dev_name": ha_entity['dev_name']}) | ||
"dev_name": ha_entity['dev_name']}) | ||
""" Return result to underliing function. """ | ||
return False | ||
return True | ||
|
@@ -151,7 +151,7 @@ def _handle_client_exception(self, callback, *args, **kwargs): | |
except (ConnectionError, RequestException) as exception: | ||
# TODO find a nice member of any exception to output | ||
self.speak_dialog('homeassistant.error', data={ | ||
'url': exception.request.url}) | ||
'url': exception.request.url}) | ||
|
||
return False | ||
|
||
|
@@ -166,14 +166,16 @@ def handle_turn_on_intent(self, message): | |
@intent_handler('turn.off.intent') | ||
def handle_turn_off_intent(self, message): | ||
self.log.debug(message.data) | ||
self.log.debug("Turn off intent on entity: "+message.data.get("entity")) | ||
self.log.debug("Turn off intent on entity: " + | ||
message.data.get("entity")) | ||
message.data["Entity"] = message.data.get("entity") | ||
message.data["Action"] = "off" | ||
self._handle_turn_actions(message) | ||
|
||
@intent_handler('toggle.intent') | ||
def handle_toggle_intent(self, message): | ||
self.log.debug("Toggle intent on entity: " + message.data.get("entity")) | ||
self.log.debug("Toggle intent on entity: " + | ||
message.data.get("entity")) | ||
message.data["Entity"] = message.data.get("entity") | ||
message.data["Action"] = "toggle" | ||
self._handle_turn_actions(message) | ||
|
@@ -186,8 +188,8 @@ def handle_sensor_intent(self, message): | |
|
||
@intent_handler('set.light.brightness.intent') | ||
def handle_light_set_intent(self, message): | ||
self.log.debug("Change light intensity: "+message.data.get("entity") \ | ||
+"to"+message.data.get("brightnessvalue")+"percent") | ||
self.log.debug("Change light intensity: "+message.data.get("entity") | ||
+ "to"+message.data.get("brightnessvalue")+"percent") | ||
message.data["Entity"] = message.data.get("entity") | ||
message.data["Brightnessvalue"] = message.data.get("brightnessvalue") | ||
self._handle_light_set(message) | ||
|
@@ -206,9 +208,54 @@ def handle_light_decrease_intent(self, message): | |
message.data["Action"] = "down" | ||
self._handle_light_adjust(message) | ||
|
||
@intent_handler('change.light.color.intent') | ||
def handle_light_color_intent(self, message): | ||
if not 'entity' in message.data: | ||
self.speak_dialog('homeassistant.device.not.given', | ||
data={"action": "change"}) | ||
return | ||
|
||
self.log.debug("Change light colour intent on entity: " + | ||
message.data['entity']) | ||
self._handle_light_color(message) | ||
|
||
def _handle_light_color(self, message): | ||
self.log.debug("Starting change colour intent.") | ||
self.log.debug("Entity: %s" % message.data["entity"]) | ||
self.log.debug("Color: %s" % message.data["color"]) | ||
|
||
entity = message.data['entity'] | ||
entity_parts = entity.split() | ||
voc_match = entity | ||
|
||
# In case the utterance is for all entities | ||
if "all" in entity_parts: | ||
voc_match = "all lights" | ||
|
||
if self.voc_match(voc_match, "all_lights"): | ||
ha_data = {'entity_id': 'all'} | ||
ha_entity = {'dev_name': 'all lights'} | ||
else: | ||
ha_entity = self._find_entity(entity, ['group', 'light']) | ||
|
||
if not ha_entity or not self._check_availability(ha_entity): | ||
return | ||
|
||
ha_data = {'entity_id': ha_entity['id']} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love if we could find a more descriptive name for this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
|
||
color = message.data['color'] | ||
color_parts = list(color.split()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaned. |
||
|
||
ha_data['color_name'] = message.data['color'] | ||
self.ha.execute_service("light", "turn_on", ha_data) | ||
|
||
ha_data['dev_name'] = ha_entity['dev_name'] | ||
self.speak_dialog('homeassistant.color.change', data=ha_data) | ||
|
||
@intent_handler('automation.intent') | ||
def handle_automation_intent(self, message): | ||
self.log.debug("Automation trigger intent on entity: "+message.data.get("entity")) | ||
self.log.debug("Automation trigger intent on entity: " + | ||
message.data.get("entity")) | ||
message.data["Entity"] = message.data.get("entity") | ||
self._handle_automation(message) | ||
|
||
|
@@ -220,14 +267,16 @@ def handle_tracker_intent(self, message): | |
|
||
@intent_handler('set.climate.intent') | ||
def handle_set_thermostat_intent(self, message): | ||
self.log.debug("Set thermostat intent on entity: "+message.data.get("entity")) | ||
self.log.debug("Set thermostat intent on entity: " + | ||
message.data.get("entity")) | ||
message.data["Entity"] = message.data.get("entity") | ||
message.data["Temp"] = message.data.get("temp") | ||
self._handle_set_thermostat(message) | ||
|
||
@intent_handler('add.item.shopping.list.intent') | ||
def handle_shopping_list_intent(self, message): | ||
self.log.debug("Add : "+message.data.get("entity")+"to the shoping list") | ||
self.log.debug("Add : "+message.data.get("entity") + | ||
"to the shoping list") | ||
message.data["Entity"] = message.data.get("entity") | ||
self._handle_shopping_list(message) | ||
|
||
|
@@ -240,9 +289,9 @@ def _handle_turn_actions(self, message): | |
|
||
# Handle turn on/off all intent | ||
try: | ||
if self.voc_match(entity,"all_lights"): | ||
if self.voc_match(entity, "all_lights"): | ||
domain = "light" | ||
elif self.voc_match(entity,"all_switches"): | ||
elif self.voc_match(entity, "all_switches"): | ||
domain = "switch" | ||
else: | ||
domain = None | ||
|
@@ -252,13 +301,15 @@ def _handle_turn_actions(self, message): | |
ha_data = {'entity_id': 'all'} | ||
|
||
self.ha.execute_service(domain, "turn_%s" % action, ha_data) | ||
self.speak_dialog('homeassistant.device.%s' % action, data=ha_entity) | ||
self.speak_dialog('homeassistant.device.%s' % | ||
action, data=ha_entity) | ||
return | ||
# TODO: need to figure out, if this indeed throws a KeyError | ||
except KeyError: | ||
self.log.debug("Not turn on/off all intent") | ||
except: | ||
self.log.debug("Unexpected error in turn all intent:", exc_info()[0]) | ||
self.log.debug( | ||
"Unexpected error in turn all intent:", exc_info()[0]) | ||
|
||
# Hande single entity | ||
|
||
|
@@ -382,14 +433,16 @@ def _handle_light_adjust(self, message): | |
'homeassistant.brightness.cantdim.dimmable', | ||
data=ha_entity) | ||
else: | ||
ha_data['brightness'] = light_attrs['unit_measure'] - brightness_value | ||
ha_data['brightness'] = light_attrs['unit_measure'] - \ | ||
brightness_value | ||
if ha_data['brightness'] < min_brightness: | ||
ha_data['brightness'] = min_brightness | ||
self.ha.execute_service("homeassistant", | ||
"turn_on", | ||
ha_data) | ||
ha_data['dev_name'] = ha_entity['dev_name'] | ||
ha_data['brightness'] = round(100 / max_brightness * ha_data['brightness']) | ||
ha_data['brightness'] = round( | ||
100 / max_brightness * ha_data['brightness']) | ||
self.speak_dialog('homeassistant.brightness.decreased', | ||
data=ha_data) | ||
elif action == "up": | ||
|
@@ -404,14 +457,16 @@ def _handle_light_adjust(self, message): | |
'homeassistant.brightness.cantdim.dimmable', | ||
data=ha_entity) | ||
else: | ||
ha_data['brightness'] = light_attrs['unit_measure'] + brightness_value | ||
ha_data['brightness'] = light_attrs['unit_measure'] + \ | ||
brightness_value | ||
if ha_data['brightness'] > max_brightness: | ||
ha_data['brightness'] = max_brightness | ||
self.ha.execute_service("homeassistant", | ||
"turn_on", | ||
ha_data) | ||
ha_data['dev_name'] = ha_entity['dev_name'] | ||
ha_data['brightness'] = round(100 / max_brightness * ha_data['brightness']) | ||
ha_data['brightness'] = round( | ||
100 / max_brightness * ha_data['brightness']) | ||
self.speak_dialog('homeassistant.brightness.increased', | ||
data=ha_data) | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Změněno {{dev_name}} na {{color_name}}. | ||
{{dev_name}} změněno na {{color_name}}. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Prosím, řekni mi které zařízení chceš ({{action}}|) | ||
Které zařízení chceš {{action}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Changed {{dev_name}} to {{color_name}}. | ||
{{dev_name}} changed to {{color_name}}. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Please, tell me which device (to {{action}}|) | ||
What device you want me to {{action}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(změň|nastav) (barvu |) {{entity}} na {{color}} | ||
(změň|nastav) {{entity}} na {{color}} (barvu|) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
change (color (of|) |) {{entity}} to {{color}} | ||
change {{entity}} (color|) to {{color}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So presently if you said:
That would see "all" and set the entity to "all lights" which presumably be all lights in the house?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, doesn't make sense, I removed the 'all' catch phrase