Hallo,
für meinen neuen Rasenmähroboter gib es eine Python-Bibliothek (pyworxcloud).
Diese habe ich so modifiziert, dass sie kein asyncio benötigt. Ich habe meine modifizierte Bibliothek im plugin-verzeichnis platziert.
Dann habe ich das sample-plugin als Startpunkt genommen und habe begonnen das Plugin zu erstellen. Wenn ich das Plugin nun aktiviere, habe ich jedoch das Problem, dass alle Plugins außer influx nicht mehr starten. Im Log sind keine Fehler zu sehen.
Ich habe dann möglichst alles was Probleme machen kann auskommentiert. Selbst so läuft es nicht mehr:
Woran liegt das? Ich hätte jetzt erwartet, dass ich wenigstens eine Fehlermeldung bekomme?
Gruß,
Hendrik
für meinen neuen Rasenmähroboter gib es eine Python-Bibliothek (pyworxcloud).
Diese habe ich so modifiziert, dass sie kein asyncio benötigt. Ich habe meine modifizierte Bibliothek im plugin-verzeichnis platziert.
Dann habe ich das sample-plugin als Startpunkt genommen und habe begonnen das Plugin zu erstellen. Wenn ich das Plugin nun aktiviere, habe ich jedoch das Problem, dass alle Plugins außer influx nicht mehr starten. Im Log sind keine Fehler zu sehen.
Ich habe dann möglichst alles was Probleme machen kann auskommentiert. Selbst so läuft es nicht mehr:
Code:
#!/usr/bin/env python3 # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab ######################################################################### # Copyright 2020- <AUTHOR> <EMAIL> ######################################################################### # This file is part of SmartHomeNG. # https://www.smarthomeNG.de # https://knx-user-forum.de/forum/supportforen/smarthome-py # # Sample plugin for new plugins to run with SmartHomeNG version 1.5 and # upwards. # # SmartHomeNG is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # SmartHomeNG is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with SmartHomeNG. If not, see <http://www.gnu.org/licenses/>. # ######################################################################### from lib.model.smartplugin import * from lib.item import Items from .webif import WebInterface #import sys #sys.path.append(".") #import py#xworxcloud # If a needed package is imported, which might be not installed in the Python environment, # add it to a requirements.txt file within the plugin's directory class SamplePlugin(SmartPlugin): """ Main class of the Plugin. Does all plugin specific stuff and provides the update functions for the items """ PLUGIN_VERSION = '1.0.0' # (must match the version specified in plugin.yaml), use '1.0.0' for your initial plugin Release def __init__(self, sh): """ Initalizes the plugin. If you need the sh object at all, use the method self.get_sh() to get it. There should be almost no need for a reference to the sh object any more. Plugins have to use the new way of getting parameter values: use the SmartPlugin method get_parameter_value(parameter_name). Anywhere within the Plugin you can get the configured (and checked) value for a parameter by calling self.get_parameter_value(parameter_name). It returns the value in the datatype that is defined in the metadata. """ # Call init code of parent class (SmartPlugin) super().__init__() # get the parameters for the plugin (as defined in metadata plugin.yaml): # self.param1 = self.get_parameter_value('param1') # cycle time in seconds, only needed, if hardware/interface needs to be # polled for value changes by adding a scheduler entry in the run method of this plugin # (maybe you want to make it a plugin parameter?) self._cycle = 60 #self.#xworx = py#xworxcloud.#xworxCloud() # Initialize connection, using your #xworx email and password #auth = #xworx.initialize("xx","yy") auth = False if not auth: #If invalid credentials are used, or something happend during #authorize, then exit self.logger.error("Authentication failed") # On initialization error use: self._init_complete = False return #Connect to device with index 0 (devices are enumerated 0, 1, 2 ...) and do #not verify SSL (False) #xworx.connect(0, True) # Initialization code goes here # if plugin should start even without web interface #self.init_webinterface(WebInterface) # if plugin should not start without web interface # if not self.init_webinterface(): # self._init_complete = False return def run(self): """ Run method for the plugin """ self.logger.debug("Run method called") # setup scheduler for device poll loop (disable the following line, if you don't need to poll the device. Rember to comment the self_cycle statement in __init__ as well) self.scheduler_add('poll_device', self.poll_device, cycle=self._cycle) self.alive = True # if you need to create child threads, do not make them daemon = True! # They will not shutdown properly. (It's a python bug) def stop(self): """ Stop method for the plugin """ self.logger.debug("Stop method called") self.scheduler_remove('poll_device') self.alive = False def parse_item(self, item): """ Default plugin parse_item method. Is called when the plugin is initialized. The plugin can, corresponding to its attribute keywords, decide what to do with the item in future, like adding it to an internal array for future reference :param item: The item to process. :return: If the plugin needs to be informed of an items change you should return a call back function like the function update_item down below. An example when this is needed is the knx plugin where parse_item returns the update_item function when the attribute knx_send is found. This means that when the items value is about to be updated, the call back function is called with the item, caller, source and dest as arguments and in case of the knx plugin the value can be sent to the knx with a knx write function within the knx plugin. """ if self.has_iattr(item.conf, 'foo_itemtag'): self.logger.debug("parse item: {}".format(item)) # todo # if interesting item for sending values: # return self.update_item def parse_logic(self, logic): """ Default plugin parse_logic method """ if 'xxx' in logic.conf: # self.function(logic['name']) pass def update_item(self, item, caller=None, source=None, dest=None): """ Item has been updated This method is called, if the value of an item has been updated by SmartHomeNG. It should write the changed value out to the device (hardware/interface) that is managed by this plugin. :param item: item to be updated towards the plugin :param caller: if given it represents the callers name :param source: if given it represents the source :param dest: if given it represents the dest """ if self.alive and caller != self.get_shortname(): # code to execute if the plugin is not stopped # and only, if the item has not been changed by this this plugin: self.logger.info("Update item: {}, item has been changed outside this plugin".format(item.id())) if self.has_iattr(item.conf, 'landroid'): self.logger.debug("update_item was called with item '{}' from caller '{}', source '{}' and dest '{}'".format(item, caller, source, dest)) if self.get_iattr_value(item.conf, 'landroid')=='rain_delay': #Set rain delay to 60 minutes #xworx.setRainDelay(60) pass if self.get_iattr_value(item.conf, 'landroid')=='start': #Start mowing routine #xworx.start() pass if self.get_iattr_value(item.conf, 'landroid')=='pause': #Pause mowing routine #xworx.pause() pass if self.get_iattr_value(item.conf, 'landroid')=='stop': #Stop and return to base #xworx.stop() pass def poll_device(self): """ Polls for updates of the device This method is only needed, if the device (hardware/interface) does not propagate changes on it's own, but has to be polled to get the actual status. It is called by the scheduler which is set within run() method. """ # # get the value from the device # device_value = ... # # # find the item(s) to update: # for item in self.sh.find_items('...'): # # # update the item by calling item(value, caller, source=None, dest=None) # # - value and caller must be specified, source and dest are optional # # # # The simple case: # item(device_value, self.get_shortname()) # # if the plugin is a gateway plugin which may receive updates from several external sources, # # the source should be included when updating the the value: # item(device_value, self.get_shortname(), source=device_source_id) #Force and update request to get latest state from the device #xworx.update() #Read latest states received from the device #xworx.getStatus() #Print all attributes received from the device #attrs = vars(#xworx) #for item in attrs: # self.logger.warning(item , ':' , attrs[item])
Gruß,
Hendrik
Kommentar