MycroftAI / adapt

Adapt Intent Parser
Apache License 2.0
712 stars 154 forks source link

Regex Matches Wonky #85

Closed btotharye closed 6 years ago

btotharye commented 6 years ago

How to submit an Issue to a Mycroft repository

Try to provide steps that we can use to replicate the Issue

On the code https://github.com/btotharye/mycroft-homeassistant/tree/add_climate I have the following regex setup:

(set) (?P<Entity>.*) thermostat to (?P<temp>[0-9]*)

From the message payload I'm getting the below which appears to be finding the temp match group but its not adding it to the actual object it appears so I get key errors when trying to get the temp:

06:56:31.758 - SKILLS - DEBUG - {"type": "mycroft.skill.handler.start", "data": {"name": "HomeAssistantSkill.handle_set_thermostat_intent"}, "context": {"target": null}}
06:56:31.813 - urllib3.connectionpool - DEBUG - http://167.99.144.205:8123 "GET /api/components HTTP/1.1" 200 297
06:56:31.815 - btotharye-home-assistant_btotharye - DEBUG - Entity: ecobee
06:56:31.815 - btotharye-home-assistant_btotharye - DEBUG - This is the message data: {'intent_type': 'btotharye-home-assistant.btotharye:SetThermostatIntent', 'btotharye_home_assistant_btotharyeClimateKeyword': 'thermostat', 'btotharye_home_assistant_btotharyetemp': '75', 'target': None, 'confidence': 0.375, '__tags__': [{'match': 'set', 'key': 'set', 'start_token': 0, 'entities': [{'key': 'set', 'match': 'set', 'data': [['set', 'mycroft_configuration_mycroftaiSetKeyword'], ['set', 'btotharye_home_assistant_btotharyeSetVerb']], 'confidence': 1.0}], 'end_token': 0, 'from_context': False}, {'start_token': 1, 'entities': [{'key': 'ecobee', 'match': 'ecobee', 'data': [['ecobee', 'btotharye_home_assistant_btotharyeEntity']], 'confidence': 0.5}], 'confidence': 0.5, 'end_token': 1, 'match': 'ecobee', 'key': 'ecobee', 'from_context': False}, {'start_token': 2, 'entities': [{'key': 'thermostat', 'match': 'thermostat', 'data': [['thermostat', 'btotharye_home_assistant_btotharyeClimateKeyword']], 'confidence': 1.0}], 'confidence': 1.0, 'end_token': 2, 'match': 'thermostat', 'key': 'thermostat', 'from_context': False}, {'start_token': 4, 'entities': [{'key': '75', 'match': '75', 'data': [['75', 'btotharye_home_assistant_btotharyetemp'], ['75', 'btotharye_home_assistant_btotharyeBrightnessValue']], 'confidence': 0.5}], 'confidence': 0.5, 'end_token': 4, 'match': '75', 'key': '75', 'from_context': False}], 'utterance': 'set ecobee thermostat to 75', 'SetVerb': 'set', 'entity': 'ecobee'}
06:56:31.820 - mycroft.skills.core:wrapper:607 - ERROR - An error occurred while processing a request in Home Assistant Skill
Traceback (most recent call last):
  File "/home/btotharye/Documents/Github/mycroft-core/mycroft/skills/core.py", line 598, in wrapper
    handler(message)
  File "/opt/mycroft/skills/btotharye-home-assistant.btotharye/__init__.py", line 441, in handle_set_thermostat_intent
    temperature = message.data["temp"]
KeyError: 'temp'

I've tried a lot of different ways but nothing ever seems to hit on this but this matches fine in Pythex and other regex verification tools. Let me know if you need anything else. The jenkins log for the build can be found at the below link which is also running the mycroft testrunner:

https://jenkins.btotharye.com/job/home_assistant_skill/108/console

The odd thing about this jenkins build is it corresponds to commit https://github.com/btotharye/mycroft-homeassistant/pull/50/commits/dba3c6975151f2a344b3929c1d3a4eea491481cc and shows the temp reading right but yet I cannot get this working on the same dev setup locally that I use in jenkins.

forslund commented 6 years ago

Can you try with (set) (?P<Entity>.*) thermostat to (?P<temp>[0-9]+) which will require a match of at least one character. adapt runs through subsets of each sentence it's passed and might trigger on an empty temp (.* allows zero character matches, while .+ requires at least one).

The order isn't guaranteed AFAIK so this can be why it works on jenkins but not at home.

Not sure if this is it but it might be worth to test.

btotharye commented 6 years ago

I'm just going to close this out I switched over to padatious to get past this for now.