Mycroft - OpenHab2 Skill

Hi @mortommy,

I’m pleased to say my Mycroft 1 is now able to control my OpenHAB2 system (yay!), and am impressed with my new ability to control devices by voice! :smiley: :sparkler:

The best part is openhab-skill connects directly to OpenHAB2 via the local REST API, without the need to go via an external MyOpenHAB portal - this architecture feels a lot more secure to me.

I’d like to report two skill bugs which I had to patch locally to get the skill working - both are likely part of recent commits to add internationalisation.

My software engineering skills are rusty, so a github pull-request is beyond me - at least for the moment! :slight_smile:

Bug 1 - “it-it” test causes SyntaxError
After finding via msm, that the openhab-mycroft skill would not start, I started debugging by looking for issues in the skill log file:

$ apt list --installed |grep mycroft-core
mycroft-core/unknown,now 0.9.13 armhf [installed]

$ vim /var/log/mycroft-skills.log

18:24:02.226 - mycroft.skills.core:load_skill:163 - ERROR - Failed to load skill: openhab-mycroft
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/mycroft_core-0.9.13-py2.7.egg/mycroft/skills/core.py", line 131, in load_skill
    skill_descriptor["name"] + MainModule, *skill_descriptor["info"])
  File "/opt/mycroft/skills/openhab-mycroft/__init__.py", line 257
    if self.lang == "it-it"
                          ^
SyntaxError: invalid syntax

My Mark 1 is set to default “en-us” (although I’m British). Adding brackets around the logical test didn’t fix the comparison, so I commented out the Italian language tests completely in init.py.
I added hash comments to lines 257-259 and 268-270.
This got further, but not quite success.

Bug 2 - SyntaxError: Non-ASCII character
The skill still threw an error:

vim /var/log/mycroft-skills.log

19:16:41.580 - mycroft.skills.core:load_skill:163 - ERROR - Failed to load skill: openhab-mycroft
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/mycroft_core-0.9.13-py2.7.egg/mycroft/skills/core.py", line 131, in load_skill
    skill_descriptor["name"] + MainModule, *skill_descriptor["info"])
  File "/opt/mycroft/skills/openhab-mycroft/__init__.py", line 265
SyntaxError: Non-ASCII character '\xc3' in file /opt/mycroft/skills/openhab-mycroft/__init__.py on line 265, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Line 265 includes a non-ASCII unicode character (requestType == "l'umidità").

Based on Python PEP0263, I added a line at the top of define a source code encoding at the top of init.py](https://github.com/openhab/openhab-mycroft/blob/master/init.py).:

> # Copyright (c) 2010-2017 by the respective copyright holders.
> # -*- coding: iso-8859-15 -*-

With the work around (commenting out “it-it”) and fix (adding encoding), the skill started, connected first time and started working. It took 10 mins and many ON / OFF tests for the novelty of speech control to wear off! :slight_smile:

Initial tests (Hey Mycroft, list openhab items) suggest openhab-skill is using the OpenHAB item file Item Name, rather than the Item Label which is not ideal as my item names are camel-case variables not designed for human-use, and especially hard to speak.

Experimentation continues… thanks for developing the binding, and hope the reports above help.