bugfix to v19 (#90)

* conversiont to python 3 Signed-off-by: Tommaso Morello tommaso.morello@gmail.com (github: mortommy)

* docs updating

* README.md changed to v18.08

* README.md changed to v18.08

* Fix multilanguage bugs 2 (#35)

* bright

bright command instead of brighten

* italian translation

added voc files for italian translation

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* intensita instead of luminosita (#36)

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com> (github: mortommy)Signed-off-by: mortommy <tommaso.morello@gmail.com>

* conversiont to python 3 Signed-oof-by: Tommaso Morello tommaso.morello@gmail.com (github: mortommy)

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* Update documentation links (#37)

Signed-off-by: Wouter Born <eclipse@maindrain.net>Signed-off-by: mortommy <tommaso.morello@gmail.com>

* docs updating

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* add German (#46)

 added german translation

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* German Translation (#42)


Signed-off-by: mortommy <tommaso.morello@gmail.com>

* Fixed typo (#48)

* Fixed typo

"Brigth -> Bright"

* Fixed typo

* Fixed typo

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* Update dimmer_command.rx (#53)


Signed-off-by: mortommy <tommaso.morello@gmail.com>

* Update dimmer_command.rx (#52)

This spelling error was identified by user **LeBelle** who has been undertaking German translations on Mycroft Translate. 
Raising PR on LeBelle's behalf.
Signed-off-by: mortommy <tommaso.morello@gmail.com>

* README.md changed to v18.08

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* README.md changed to v18.08

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* added "turn x on/off" as a command (#56)

It feels more natural for me to say turn light on instead of turn on light x
Signed-off-by: mortommy <tommaso.morello@gmail.com>

* added spanish support. Signed-off-by: Tommaso Morello tommaso.morello@gmail.com (github: mortommy)

Signed-off-by: mortommy <tommaso.morello@gmail.com>

* Revert "Add spanish"

* added spanish support. Signed-off-by: Tommaso Morello tommaso.morello@gmail.com (github: mortommy)

* Revert "Add spanish"

* added spanish support. Signed-off-by: Tommaso Morello tommaso.morello@gmail.com (github: mortommy)

* added spanish support. Signed-off-by: Tommaso Morello tommaso.morello@gmail.com (github: mortommy)

* Fix supported languages list

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Revert "Fix supported languages list"

* Fix supported languages list

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Fix languages values

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* tuning what status intent. switch to padatious

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Convert what_status intent to padatious. Apply review from Mycroft team. Add new files

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Bug fix

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Bug fix 2

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Bug fix 3

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Bug fix 4

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* dimmer command regex fix

Signed-off-by: Tommaso Morello <tommaso.morello@gmail.com>

* Bug fix V19

Signed-off-by: mortommy <tommaso.morello@gmail.com>

Co-authored-by: Wouter Born <github@maindrain.net>
Co-authored-by: Andreas Reinle <gras64@web.de>
Co-authored-by: Sawyer McLane <samclane@gmail.com>
Co-authored-by: Kathy Reid <kathy@kathyreid.id.au>
Co-authored-by: Fabian Pflug <gumulka@users.noreply.github.com>
pull/91/head
mortommy 2020-04-07 16:09:14 +02:00 committed by GitHub
parent f15b90c266
commit 6ed5b806ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 417 additions and 452 deletions

View File

@ -1,432 +1,397 @@
# -*- coding: iso-8859-15 -*- # -*- coding: iso-8859-15 -*-
# #
# Copyright (c) 2010-2019 Contributors to the openHAB project # Copyright (c) 2010-2019 Contributors to the openHAB project
# #
# See the NOTICE file(s) distributed with this work for additional # See the NOTICE file(s) distributed with this work for additional
# information. # information.
# #
# This program and the accompanying materials are made available under the # This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at # terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0 # http://www.eclipse.org/legal/epl-2.0
# #
# SPDX-License-Identifier: EPL-2.0 # SPDX-License-Identifier: EPL-2.0
# #
from os.path import dirname from os.path import dirname
from adapt.intent import IntentBuilder from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill, intent_handler from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft.util.log import getLogger from mycroft.util.log import getLogger
from fuzzywuzzy import fuzz from fuzzywuzzy import fuzz
import requests import requests
import json import json
# v 0.1 - just switch on and switch off a fix light # v 0.1 - just switch on and switch off a fix light
# v 0.2 - code review # v 0.2 - code review
# v 0.3 - first working version on fixed light item # v 0.3 - first working version on fixed light item
# v 0.4 - getTaggedItems method in order to get all the tagged items from openHAB # v 0.4 - getTaggedItems method in order to get all the tagged items from openHAB
# v 0.5 - refresh tagged item intent # v 0.5 - refresh tagged item intent
# v 0.6 - add findItemName method and import fuzzywuzzy # v 0.6 - add findItemName method and import fuzzywuzzy
# v 0.7 - add intent for switchable items # v 0.7 - add intent for switchable items
# v 0.8 - merged lighting and switchable intent in onoff intent # v 0.8 - merged lighting and switchable intent in onoff intent
# v 0.9 - added support to dimmable items # v 0.9 - added support to dimmable items
# v 1.0 - added Thermostat tag support # v 1.0 - added Thermostat tag support
# v 1.1 - added what status Switchable tag # v 1.1 - added what status Switchable tag
# v 1.2 - support to python 3.0 # v 1.2 - support to python 3.0
# v 1.3 - support german # v 1.3 - support german
# v 1.4 - support spanish # v 1.4 - support spanish
# v 1.5 - support to 19 # v 1.5 - support to 19
__author__ = 'mortommy' __author__ = 'mortommy'
LOGGER = getLogger(__name__) LOGGER = getLogger(__name__)
class openHABSkill(MycroftSkill): class openHABSkill(MycroftSkill):
def __init__(self): def __init__(self):
super(openHABSkill, self).__init__(name="openHABSkill") super(openHABSkill, self).__init__(name="openHABSkill")
self.command_headers = {"Content-type": "text/plain"} self.command_headers = {"Content-type": "text/plain"}
self.polling_headers = {"Accept": "application/json"} self.polling_headers = {"Accept": "application/json"}
self.url = None self.url = None
self.lightingItemsDic = dict() self.lightingItemsDic = dict()
self.switchableItemsDic = dict() self.switchableItemsDic = dict()
self.currentTempItemsDic = dict() self.currentTempItemsDic = dict()
self.currentHumItemsDic = dict() self.currentHumItemsDic = dict()
#self.currentThermostatItemsDic = dict() #self.currentThermostatItemsDic = dict()
self.targetTemperatureItemsDic = dict() self.targetTemperatureItemsDic = dict()
#self.homekitHeatingCoolingModeDic = dict() #self.homekitHeatingCoolingModeDic = dict()
def initialize(self): def initialize(self):
supported_languages = ["en-us", "it-it", "de-de", "es-es"] supported_languages = ["en-us", "it-it", "de-de", "es-es"]
if self.lang not in supported_languages: if self.lang not in supported_languages:
self.log.warning("Unsupported language for " + self.name + ", shutting down skill.") self.log.warning("Unsupported language for " + self.name + ", shutting down skill.")
self.shutdown() self.shutdown()
self.handle_websettings_update() self.handle_websettings_update()
if self.url is not None: if self.url is not None:
self.getTaggedItems() self.getTaggedItems()
else: else:
self.speak_dialog('ConfigurationNeeded') self.speak_dialog('ConfigurationNeeded')
refresh_tagged_items_intent = IntentBuilder("RefreshTaggedItemsIntent").require("RefreshTaggedItemsKeyword").build() refresh_tagged_items_intent = IntentBuilder("RefreshTaggedItemsIntent").require("RefreshTaggedItemsKeyword").build()
self.register_intent(refresh_tagged_items_intent, self.handle_refresh_tagged_items_intent) self.register_intent(refresh_tagged_items_intent, self.handle_refresh_tagged_items_intent)
onoff_status_intent = IntentBuilder("OnOff_StatusIntent").require("OnOffStatusKeyword").require("Command").require("Item").build() onoff_status_intent = IntentBuilder("OnOff_StatusIntent").require("OnOffStatusKeyword").require("Command").require("Item").build()
self.register_intent(onoff_status_intent, self.handle_onoff_status_intent) self.register_intent(onoff_status_intent, self.handle_onoff_status_intent)
dimmer_status_intent = IntentBuilder("Dimmer_StatusIntent").require("DimmerStatusKeyword").require("Item").optionally("BrightPercentage").build() dimmer_status_intent = IntentBuilder("Dimmer_StatusIntent").require("DimmerStatusKeyword").require("Item").optionally("BrightPercentage").build()
self.register_intent(dimmer_status_intent, self.handle_dimmer_status_intent) self.register_intent(dimmer_status_intent, self.handle_dimmer_status_intent)
#what_status_intent = IntentBuilder("What_StatusIntent").require("WhatStatusKeyword").require("Item").require("RequestType").build() #what_status_intent = IntentBuilder("What_StatusIntent").require("WhatStatusKeyword").require("Item").require("RequestType").build()
#self.register_intent(what_status_intent, self.handle_what_status_intent) #self.register_intent(what_status_intent, self.handle_what_status_intent)
self.register_entity_file('item.entity') self.register_entity_file('item.entity')
self.register_entity_file('requesttype.entity') self.register_entity_file('requesttype.entity')
self.register_intent_file('what.status.intent',self.handle_what_status_intent) self.register_intent_file('what.status.intent',self.handle_what_status_intent)
setTemp_status_intent = IntentBuilder("SetTemp_StatusIntent").require("ThermostatStatusKeyword").require("Item").require("TempValue").build() setTemp_status_intent = IntentBuilder("SetTemp_StatusIntent").require("ThermostatStatusKeyword").require("Item").require("TempValue").build()
self.register_intent(setTemp_status_intent, self.handle_setTemp_status_intent) self.register_intent(setTemp_status_intent, self.handle_setTemp_status_intent)
list_items_intent = IntentBuilder("ListItemsIntent").require("ListItemsKeyword").build() list_items_intent = IntentBuilder("ListItemsIntent").require("ListItemsKeyword").build()
self.register_intent(list_items_intent, self.handle_list_items_intent) self.register_intent(list_items_intent, self.handle_list_items_intent)
self.settings_change_callback = self.handle_websettings_update self.settings_change_callback = self.handle_websettings_update
def get_config(self, key): def get_config(self, key):
return (self.settings.get(key) or self.config_core.get('openHABSkill', {}).get(key)) return (self.settings.get(key) or self.config_core.get('openHABSkill', {}).get(key))
def handle_websettings_update(self): def handle_websettings_update(self):
if self.get_config('host') is not None and self.get_config('port') is not None: if self.get_config('host') is not None and self.get_config('port') is not None:
self.url = "http://%s:%s/rest" % (self.get_config('host'), self.get_config('port')) self.url = "http://%s:%s/rest" % (self.get_config('host'), self.get_config('port'))
self.getTaggedItems() self.getTaggedItems()
else: else:
self.url = None self.url = None
def getTaggedItems(self): def getTaggedItems(self):
#find all the items tagged Lighting and Switchable from openHAB #find all the items tagged Lighting and Switchable from openHAB
#the labeled items are stored in dictionaries #the labeled items are stored in dictionaries
self.lightingItemsDic = {} self.lightingItemsDic = {}
self.switchableItemsDic = {} self.switchableItemsDic = {}
self.currentTempItemsDic = {} self.currentTempItemsDic = {}
self.currentHumItemsDic = {} self.currentHumItemsDic = {}
self.currentThermostatItemsDic = {} self.currentThermostatItemsDic = {}
self.targetTemperatureItemsDic = {} self.targetTemperatureItemsDic = {}
self.homekitHeatingCoolingModeDic = {} self.homekitHeatingCoolingModeDic = {}
requestUrl = self.url+"/items?recursive=false" if self.url == None:
LOGGER.error("Configuration needed!")
try: self.speak_dialog('ConfigurationNeeded')
req = requests.get(requestUrl, headers=self.polling_headers) else:
if req.status_code == 200: requestUrl = self.url+"/items?recursive=false"
json_response = req.json()
for x in range(0,len(json_response)): try:
if ("Lighting" in json_response[x]['tags']): req = requests.get(requestUrl, headers=self.polling_headers)
self.lightingItemsDic.update({json_response[x]['name']: json_response[x]['label']}) if req.status_code == 200:
elif ("Switchable" in json_response[x]['tags']): json_response = req.json()
self.switchableItemsDic.update({json_response[x]['name']: json_response[x]['label']}) for x in range(0,len(json_response)):
elif ("CurrentTemperature" in json_response[x]['tags']): if ("Lighting" in json_response[x]['tags']):
self.currentTempItemsDic.update({json_response[x]['name']: json_response[x]['label']}) self.lightingItemsDic.update({json_response[x]['name']: json_response[x]['label']})
elif ("CurrentHumidity" in json_response[x]['tags']): elif ("Switchable" in json_response[x]['tags']):
self.currentHumItemsDic.update({json_response[x]['name']: json_response[x]['label']}) self.switchableItemsDic.update({json_response[x]['name']: json_response[x]['label']})
elif ("Thermostat" in json_response[x]['tags']): elif ("CurrentTemperature" in json_response[x]['tags']):
self.currentThermostatItemsDic.update({json_response[x]['name']: json_response[x]['label']}) self.currentTempItemsDic.update({json_response[x]['name']: json_response[x]['label']})
elif ("TargetTemperature" in json_response[x]['tags']): elif ("CurrentHumidity" in json_response[x]['tags']):
self.targetTemperatureItemsDic.update({json_response[x]['name']: json_response[x]['label']}) self.currentHumItemsDic.update({json_response[x]['name']: json_response[x]['label']})
elif ("homekit:HeatingCoolingMode" in json_response[x]['tags']): elif ("Thermostat" in json_response[x]['tags']):
self.homekitHeatingCoolingModeDic.update({json_response[x]['name']: json_response[x]['label']}) self.currentThermostatItemsDic.update({json_response[x]['name']: json_response[x]['label']})
else: elif ("TargetTemperature" in json_response[x]['tags']):
pass self.targetTemperatureItemsDic.update({json_response[x]['name']: json_response[x]['label']})
else: elif ("homekit:HeatingCoolingMode" in json_response[x]['tags']):
LOGGER.error("Some issues with the command execution!") self.homekitHeatingCoolingModeDic.update({json_response[x]['name']: json_response[x]['label']})
self.speak_dialog('GetItemsListError') else:
pass
except KeyError: else:
pass LOGGER.error("Some issues with the command execution!")
except Exception: self.speak_dialog('GetItemsListError')
LOGGER.error("Some issues with the command execution!")
self.speak_dialog('GetItemsListError') except KeyError:
pass
def findItemName(self, itemDictionary, messageItem): except Exception:
LOGGER.error("Some issues with the command execution!")
bestScore = 0 self.speak_dialog('GetItemsListError')
score = 0
bestItem = None def findItemName(self, itemDictionary, messageItem):
try: bestScore = 0
for itemName, itemLabel in list(itemDictionary.items()): score = 0
score = fuzz.ratio(messageItem, itemLabel) bestItem = None
if score > bestScore:
bestScore = score try:
bestItem = itemName for itemName, itemLabel in list(itemDictionary.items()):
except KeyError: score = fuzz.ratio(messageItem, itemLabel)
pass if score > bestScore:
bestScore = score
return bestItem bestItem = itemName
except KeyError:
pass
def getItemsFromDict(self, typeStr, itemsDict):
if len(itemsDict) == 0: return bestItem
return ""
else:
return "%s: %s" % (typeStr, ', '.join(list(itemsDict.values()))) def getItemsFromDict(self, typeStr, itemsDict):
if len(itemsDict) == 0:
def handle_list_items_intent(self, message): return ""
msg = self.getItemsFromDict("Lights", self.lightingItemsDic) + "\n" else:
msg = msg.strip() + ' ' + self.getItemsFromDict("Switches", self.switchableItemsDic) + "\n" return "%s: %s" % (typeStr, ', '.join(list(itemsDict.values())))
msg = msg.strip() + ' ' + self.getItemsFromDict("Current Temperature", self.currentTempItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Current Humidity", self.currentHumItemsDic) + "\n" def handle_list_items_intent(self, message):
msg = msg.strip() + ' ' + self.getItemsFromDict("Thermostat", self.currentThermostatItemsDic) + "\n" msg = self.getItemsFromDict("Lights", self.lightingItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Target Temperature", self.targetTemperatureItemsDic) + "\n" msg = msg.strip() + ' ' + self.getItemsFromDict("Switches", self.switchableItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Homekit Heating and Cooling", self.homekitHeatingCoolingModeDic) msg = msg.strip() + ' ' + self.getItemsFromDict("Current Temperature", self.currentTempItemsDic) + "\n"
self.speak_dialog('FoundItems', {'items': msg.strip()}) msg = msg.strip() + ' ' + self.getItemsFromDict("Current Humidity", self.currentHumItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Thermostat", self.currentThermostatItemsDic) + "\n"
def handle_refresh_tagged_items_intent(self, message): msg = msg.strip() + ' ' + self.getItemsFromDict("Target Temperature", self.targetTemperatureItemsDic) + "\n"
#to refresh the openHAB items labeled list we use an intent, we can ask Mycroft to make the refresh msg = msg.strip() + ' ' + self.getItemsFromDict("Homekit Heating and Cooling", self.homekitHeatingCoolingModeDic)
self.speak_dialog('FoundItems', {'items': msg.strip()})
self.getTaggedItems()
dictLenght = str(len(self.lightingItemsDic) + len(self.switchableItemsDic) + len(self.currentTempItemsDic) + len(self.currentHumItemsDic) + len(self.currentThermostatItemsDic) + len(self.targetTemperatureItemsDic) + len(self.homekitHeatingCoolingModeDic)) def handle_refresh_tagged_items_intent(self, message):
self.speak_dialog('RefreshTaggedItems', {'number_item': dictLenght}) #to refresh the openHAB items labeled list we use an intent, we can ask Mycroft to make the refresh
def handle_onoff_status_intent(self, message): self.getTaggedItems()
command = message.data.get('Command') dictLenght = str(len(self.lightingItemsDic) + len(self.switchableItemsDic) + len(self.currentTempItemsDic) + len(self.currentHumItemsDic) + len(self.currentThermostatItemsDic) + len(self.targetTemperatureItemsDic) + len(self.homekitHeatingCoolingModeDic))
messageItem = message.data.get('Item') self.speak_dialog('RefreshTaggedItems', {'number_item': dictLenght})
#We have to find the item to update from our dictionaries def handle_onoff_status_intent(self, message):
self.lightingSwitchableItemsDic = dict() command = message.data.get('Command')
self.lightingSwitchableItemsDic.update(self.lightingItemsDic) messageItem = message.data.get('Item')
self.lightingSwitchableItemsDic.update(self.switchableItemsDic)
#We have to find the item to update from our dictionaries
ohItem = self.findItemName(self.lightingSwitchableItemsDic, messageItem) self.lightingSwitchableItemsDic = dict()
self.lightingSwitchableItemsDic.update(self.lightingItemsDic)
if ohItem != None: self.lightingSwitchableItemsDic.update(self.switchableItemsDic)
if (command != "on") and (command != "off"):
self.speak_dialog('ErrorDialog') ohItem = self.findItemName(self.lightingSwitchableItemsDic, messageItem)
else:
statusCode = self.sendCommandToItem(ohItem, command.upper()) if ohItem != None:
if statusCode == 200: if (command != "on") and (command != "off"):
self.speak_dialog('StatusOnOff', {'command': command, 'item': messageItem}) self.speak_dialog('ErrorDialog')
elif statusCode == 404: else:
LOGGER.error("Some issues with the command execution!. Item not found") statusCode = self.sendCommandToItem(ohItem, command.upper())
self.speak_dialog('ItemNotFoundError') if statusCode == 200:
else: self.speak_dialog('StatusOnOff', {'command': command, 'item': messageItem})
LOGGER.error("Some issues with the command execution!") elif statusCode == 404:
self.speak_dialog('CommunicationError') LOGGER.error("Some issues with the command execution!. Item not found")
else: self.speak_dialog('ItemNotFoundError')
LOGGER.error("Item not found!") else:
self.speak_dialog('ItemNotFoundError') LOGGER.error("Some issues with the command execution!")
self.speak_dialog('CommunicationError')
def handle_dimmer_status_intent(self, message): else:
command = message.data.get('DimmerStatusKeyword') LOGGER.error("Item not found!")
messageItem = message.data.get('Item') self.speak_dialog('ItemNotFoundError')
brightValue = message.data.get('BrightPercentage', None)
def handle_dimmer_status_intent(self, message):
statusCode = 0 command = message.data.get('DimmerStatusKeyword')
newBrightValue = 0 messageItem = message.data.get('Item')
brightValue = message.data.get('BrightPercentage', None)
ohItem = self.findItemName(self.lightingItemsDic, messageItem)
statusCode = 0
if ohItem != None: newBrightValue = 0
#if ((command == "set") or (command == "imposta") or (command == "setze") or (command == "pone")):
if self.voc_match(command, 'Set'): ohItem = self.findItemName(self.lightingItemsDic, messageItem)
if ((brightValue == None) or (int(brightValue) < 0) or (int(brightValue) > 100)):
self.speak_dialog('ErrorDialog') if ohItem != None:
else: #if ((command == "set") or (command == "imposta") or (command == "setze") or (command == "pone")):
statusCode = self.sendCommandToItem(ohItem, brightValue) if self.voc_match(command, 'Set'):
else: if ((brightValue == None) or (int(brightValue) < 0) or (int(brightValue) > 100)):
#find current item statusCode self.speak_dialog('ErrorDialog')
state = self.getCurrentItemStatus(ohItem) else:
if (state != None): statusCode = self.sendCommandToItem(ohItem, brightValue)
#dim or brighten the value else:
curBrightList = state.split(',') #find current item statusCode
curBright = int(curBrightList[len(curBrightList)-1]) state = self.getCurrentItemStatus(ohItem)
if (state != None):
if(brightValue == None): #dim or brighten the value
brightValue = "10" curBrightList = state.split(',')
curBright = int(curBrightList[len(curBrightList)-1])
#if ((command == "dim") or (command == "abbassa") or (command == "dimme") or (command == "oscurece")):
if self.voc_match(command, 'Dim'): if(brightValue == None):
newBrightValue = curBright-(int(brightValue)) brightValue = "10"
else:
newBrightValue = curBright+(int(brightValue)) #if ((command == "dim") or (command == "abbassa") or (command == "dimme") or (command == "oscurece")):
if self.voc_match(command, 'Dim'):
if (newBrightValue < 0): newBrightValue = curBright-(int(brightValue))
newBrightValue = 0 else:
elif (newBrightValue > 100): newBrightValue = curBright+(int(brightValue))
newBrightValue = 100
else: if (newBrightValue < 0):
pass newBrightValue = 0
elif (newBrightValue > 100):
#send command to item newBrightValue = 100
statusCode = self.sendCommandToItem(ohItem, str(newBrightValue)) else:
else: pass
pass
#send command to item
if statusCode == 200: statusCode = self.sendCommandToItem(ohItem, str(newBrightValue))
self.speak_dialog('StatusDimmer', {'item': messageItem}) else:
elif statusCode == 404: pass
LOGGER.error("Some issues with the command execution!. Item not found")
self.speak_dialog('ItemNotFoundError') if statusCode == 200:
else: self.speak_dialog('StatusDimmer', {'item': messageItem})
LOGGER.error("Some issues with the command execution!") elif statusCode == 404:
self.speak_dialog('CommunicationError') LOGGER.error("Some issues with the command execution!. Item not found")
self.speak_dialog('ItemNotFoundError')
else: else:
LOGGER.error("Item not found!") LOGGER.error("Some issues with the command execution!")
self.speak_dialog('ItemNotFoundError') self.speak_dialog('CommunicationError')
def handle_what_status_intent(self, message): else:
LOGGER.error("Item not found!")
messageItem = message.data.get('item') self.speak_dialog('ItemNotFoundError')
LOGGER.debug("Item: %s" % (messageItem))
requestType = message.data.get('requesttype') def handle_what_status_intent(self, message):
LOGGER.debug("Request Type: %s" % (requestType))
messageItem = message.data.get('item')
unitOfMeasure = self.translate('Degree') LOGGER.debug("Item: %s" % (messageItem))
#unitOfMeasure = "degree" requestType = message.data.get('requesttype')
infoType = self.translate('Temperature') LOGGER.debug("Request Type: %s" % (requestType))
#infoType = "temperature"
unitOfMeasure = self.translate('Degree')
# if (self.lang == "it-it"): infoType = self.translate('Temperature')
# unitOfMeasure = "gradi"
# infoType = "temperatura" self.currStatusItemsDic = dict()
# if (self.lang == "de-de"): if self.voc_match(requestType, 'Temperature'):
# unitOfMeasure = "Grad" self.currStatusItemsDic.update(self.currentTempItemsDic)
# infoType = "Temperatur" elif self.voc_match(requestType, 'Humidity'):
unitOfMeasure = self.translate('Percentage')
# if (self.lang == "es-es"): infoType = self.translate('Humidity')
# unitOfMeasure = "grados" self.currStatusItemsDic.update(self.currentHumItemsDic)
# infoType = "temperatura" elif self.voc_match(requestType, 'Status'):
infoType = self.translate('Status')
self.currStatusItemsDic = dict() unitOfMeasure = ""
self.currStatusItemsDic.update(self.switchableItemsDic)
#if((requestType == "temperature") or (requestType == "la temperatura") or (requestType == "temperatur") or (requestType == "temperatura")): else:
if self.voc_match(requestType, 'Temperature'): self.currStatusItemsDic.update(self.targetTemperatureItemsDic)
self.currStatusItemsDic.update(self.currentTempItemsDic)
#elif((requestType == "humidity") or (requestType == "l'umidità") or (requestType == "Feuchtigkeit") or (requestType == "humedad")): ohItem = self.findItemName(self.currStatusItemsDic, messageItem)
elif self.voc_match(requestType, 'Humidity'):
#unitOfMeasure = "percentage" if ohItem != None:
unitOfMeasure = self.translate('Percentage') state = self.getCurrentItemStatus(ohItem)
#infoType = "humidity" self.speak_dialog('TempHumStatus', {'item': messageItem, 'temp_hum': infoType, 'temp_hum_val': state, 'units_of_measurement': unitOfMeasure})
infoType = self.translate('Humidity') else:
# if (self.lang == "it-it"): LOGGER.error("Item not found!")
# unitOfMeasure = "percento" self.speak_dialog('ItemNotFoundError')
# infoType = "umidità"
# if (self.lang == "de-de"): def handle_setTemp_status_intent(self, message):
# unitOfMeasure = "Prozentsatz" command = message.data.get('ThermostatStatusKeyword')
# infoType = "Feuchtigkeit" messageItem = message.data.get('Item')
# if (self.lang == "es-es"): tempVal = message.data.get('TempValue')
# unitOfMeasure = "porciento"
# infoType = "humedad" statusCode = 0
self.currStatusItemsDic.update(self.currentHumItemsDic) newTempValue = 0
#elif((requestType == "status") or (requestType == "lo stato") or (requestType == "Status") or (requestType == "estado")):
elif self.voc_match(requestType, 'Status'): ohItem = self.findItemName(self.targetTemperatureItemsDic, messageItem)
#infoType = "status"
infoType = self.translate('Status') if ohItem != None:
unitOfMeasure = "" if self.voc_match(command, 'Regulate'):
# if (self.lang == "it-it"): statusCode = self.sendCommandToItem(ohItem, tempVal)
# unitOfMeasure = "stato" newTempValue = tempVal
else:
# if (self.lang == "de-de"): state = self.getCurrentItemStatus(ohItem)
# unitOfMeasure = "Status" if ((state != None) and (state.isdigit())):
if self.voc_match(command, 'Increase'):
# if (self.lang == "es-es"): newTempValue = int(state)+(int(tempVal))
# unitOfMeasure = "estado" else:
self.currStatusItemsDic.update(self.switchableItemsDic) newTempValue = int(state)-(int(tempVal))
else:
self.currStatusItemsDic.update(self.targetTemperatureItemsDic) statusCode = self.sendCommandToItem(ohItem, str(newTempValue))
else:
ohItem = self.findItemName(self.currStatusItemsDic, messageItem) pass
if ohItem != None: if statusCode == 200:
state = self.getCurrentItemStatus(ohItem) self.speak_dialog('ThermostatStatus', {'item': messageItem, 'temp_val': str(newTempValue)})
self.speak_dialog('TempHumStatus', {'item': messageItem, 'temp_hum': infoType, 'temp_hum_val': state, 'units_of_measurement': unitOfMeasure}) elif statusCode == 404:
else: LOGGER.error("Some issues with the command execution! Item not found")
LOGGER.error("Item not found!") self.speak_dialog('ItemNotFoundError')
self.speak_dialog('ItemNotFoundError') else:
LOGGER.error("Some issues with the command execution!")
def handle_setTemp_status_intent(self, message): self.speak_dialog('CommunicationError')
command = message.data.get('ThermostatStatusKeyword')
messageItem = message.data.get('Item') else:
tempVal = message.data.get('TempValue') LOGGER.error("Item not found!")
self.speak_dialog('ItemNotFoundError')
statusCode = 0
newTempValue = 0 def sendStatusToItem(self, ohItem, command):
requestUrl = self.url+"/items/%s/state" % (ohItem)
ohItem = self.findItemName(self.targetTemperatureItemsDic, messageItem) req = requests.put(requestUrl, data=command, headers=self.command_headers)
if ohItem != None: return req.status_code
#if((command == "regulate") or (command == "adjust") or (command == "tune") or (command == "regola") or (command == "aggiusta") or (command == "metti") or (command == "reguliere") or (command == "stell") or (command == "pass") or (command == "regula") or (command == "ajusta") or (command == "afina")):
if self.voc_match(command, 'Regulate'): def sendCommandToItem(self, ohItem, command):
statusCode = self.sendCommandToItem(ohItem, tempVal) requestUrl = self.url+"/items/%s" % (ohItem)
newTempValue = tempVal req = requests.post(requestUrl, data=command, headers=self.command_headers)
else:
state = self.getCurrentItemStatus(ohItem) return req.status_code
if ((state != None) and (state.isdigit())):
#if ((command == "increase") or (command == "incrementa") or (command == "erhöhe") or (command == "aumenta")): def getCurrentItemStatus(self, ohItem):
if self.voc_match(command, 'Increase'): requestUrl = self.url+"/items/%s/state" % (ohItem)
newTempValue = int(state)+(int(tempVal)) state = None
else:
newTempValue = int(state)-(int(tempVal)) try:
req = requests.get(requestUrl, headers=self.command_headers)
statusCode = self.sendCommandToItem(ohItem, str(newTempValue))
else: if req.status_code == 200:
pass state = req.text
else:
if statusCode == 200: LOGGER.error("Some issues with the command execution!")
self.speak_dialog('ThermostatStatus', {'item': messageItem, 'temp_val': str(newTempValue)}) self.speak_dialog('CommunicationError')
elif statusCode == 404:
LOGGER.error("Some issues with the command execution! Item not found") except KeyError:
self.speak_dialog('ItemNotFoundError') pass
else:
LOGGER.error("Some issues with the command execution!") return state
self.speak_dialog('CommunicationError')
def stop(self):
else: pass
LOGGER.error("Item not found!")
self.speak_dialog('ItemNotFoundError') def create_skill():
return openHABSkill()
def sendStatusToItem(self, ohItem, command):
requestUrl = self.url+"/items/%s/state" % (ohItem)
req = requests.put(requestUrl, data=command, headers=self.command_headers)
return req.status_code
def sendCommandToItem(self, ohItem, command):
requestUrl = self.url+"/items/%s" % (ohItem)
req = requests.post(requestUrl, data=command, headers=self.command_headers)
return req.status_code
def getCurrentItemStatus(self, ohItem):
requestUrl = self.url+"/items/%s/state" % (ohItem)
state = None
try:
req = requests.get(requestUrl, headers=self.command_headers)
if req.status_code == 200:
state = req.text
else:
LOGGER.error("Some issues with the command execution!")
self.speak_dialog('CommunicationError')
except KeyError:
pass
return state
def stop(self):
pass
def create_skill():
return openHABSkill()

View File

@ -1,8 +1,8 @@
(was ist|wie ist|worauf ist) (der|die|) {item} {requesttype} (was ist|wie ist|worauf ist) (der|die) {item} {requesttype}
(was ist|wie ist|worauf ist) (der|die|) {requesttype} des {item} (was ist|wie ist|worauf ist) (der|die) {requesttype} des {item}
Sag mir (der|die|) {item} {requesttype} Sag mir (der|die) {item} {requesttype}
Sag mir (der|die|) {requesttype} des {item} Sag mir (der|die) {requesttype} des {item}
Sag mir wie ist (der|die|) {item} {requesttype} Sag mir wie ist (der|die) {item} {requesttype}
Ich möchte wissen (der|die|) {item} {requesttype} Ich möchte wissen (der|die) {item} {requesttype}
Ich möchte wissen (der|die|) {requesttype} des {item} Ich möchte wissen (der|die) {requesttype} des {item}
Ich möchte wissen wie ist (der|die|) {item} {requesttype} Ich möchte wissen wie ist (der|die) {item} {requesttype}

View File

@ -1,9 +1,9 @@
(what's|what is) (the|) {item} {requesttype} (what's|what is) the {item} {requesttype}
(what's|what is) (the|) {requesttype} of {item} (what's|what is) the {requesttype} of {item}
how (the| ) {item} is {requesttype} how the {item} is {requesttype}
tell me (the|) {item} {requesttype} tell me the {item} {requesttype}
tell me (the|) {requesttype} of {item} tell me the {requesttype} of {item}
tell me how (the|) {item} is {requesttype} tell me how the {item} is {requesttype}
I'd like to know {item} {requesttype} I'd like to know the {item} {requesttype}
I'd like to know (the|) {requesttype} of {item} I'd like to know the {requesttype} of {item}
I'd like to know how (the|) {item} is {requesttype} I'd like to know how the {item} is {requesttype}

View File

@ -1,3 +1,3 @@
(quale è|qual'è|com'è|come è) {requesttype} {item} (quale è|qual'è|com'è|come è) (la|lo|l'|) {requesttype} {item}
vorrei sapere (quale è|qual'è|com'è|come è|) {requesttype} {item} vorrei sapere (quale è|qual'è|com'è|come è|) (la|lo|l'|) {requesttype} {item}
dimmmi (quale è|qual'è|com'è|come è|) {requesttype} {item} dimmmi (quale è|qual'è|com'è|come è|) (la|lo|l'|) {requesttype} {item}