Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/smarthomeNG/plugins into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
aschwith committed Sep 18, 2023
2 parents e181c4a + 40953f2 commit 9b057f4
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 432 deletions.
218 changes: 0 additions & 218 deletions unifi/README.md

This file was deleted.

92 changes: 5 additions & 87 deletions unifi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#########################################################################
# This file is part of SmartHomeNG.
#
# Sample plugin for new plugins to run with SmartHomeNG version 1.4 and
# upwards.
# Plugin to read and control some features of UniFi Controllers
#
# SmartHomeNG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -29,6 +28,7 @@
import cherrypy
from lib.module import Modules
from lib.model.smartplugin import *
from .webif import WebInterface
from lib.utils import Utils
from plugins.unifi.ubiquiti.unifi import API as UniFiAPI
from plugins.unifi.ubiquiti.unifi import DataException as UniFiDataException
Expand Down Expand Up @@ -289,13 +289,13 @@ class UniFiControllerClient(SmartPlugin):
the update functions for the items
"""

PLUGIN_VERSION = '1.6.2'
PLUGIN_VERSION = '1.6.3'

def __init__(self, sh, *args, **kwargs):
"""
Initalizes the plugin. The parameters describe for this method are pulled from the entry in plugin.yaml.
"""

super().__init__()
from bin.smarthome import VERSION
if '.'.join(VERSION.split('.', 2)[:2]) <= '1.5':
self.logger = logging.getLogger(__name__)
Expand All @@ -319,7 +319,7 @@ def __init__(self, sh, *args, **kwargs):
self._cycle = self.get_parameter_value(UniFiConst.PARAMETER_CYCLE_TIME)
self._logging = True

self.init_webinterface()
self.init_webinterface(WebInterface)

return

Expand Down Expand Up @@ -657,85 +657,3 @@ def poll_device(self):
except ConnectionError as ex:
self._pollfailed += 1
self.logger.error("Poll failed: {} for {} time(s) in a row.".format(repr(ex), self._pollfailed))

def init_webinterface(self):
""""
Initialize the web interface for this plugin
This method is only needed if the plugin is implementing a web interface
"""
try:
# try/except to handle running in a core version that does not support modules
self.mod_http = Modules.get_instance().get_module('http')
except:
self.mod_http = None
if self.mod_http == None:
self.logger.error("Not initializing the web interface")
return False

import sys
if not "SmartPluginWebIf" in list(sys.modules['lib.model.smartplugin'].__dict__):
self.logger.warning("Web interface needs SmartHomeNG v1.5 and up. Not initializing the web interface")
return False

# set application configuration for cherrypy
webif_dir = self.path_join(self.get_plugin_dir(), 'webif')
config = {
'/': {
'tools.staticdir.root': webif_dir,
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': 'static'
}
}

# Register the web interface as a cherrypy app
self.mod_http.register_webif(WebInterface(webif_dir, self),
self.get_shortname(),
config,
self.get_classname(), self.get_instance_name(),
description='')

return True


# ------------------------------------------
# Webinterface of the plugin
# ------------------------------------------


class WebInterface(SmartPluginWebIf):

def __init__(self, webif_dir, plugin):
"""
Initialization of instance of class WebInterface
:param webif_dir: directory where the webinterface of the plugin resides
:param plugin: instance of the plugin
:type webif_dir: str
:type plugin: object
"""
self.logger = logging.getLogger(__name__)
self.webif_dir = webif_dir
self.plugin = plugin
self.tplenv = self.init_template_environment()

@cherrypy.expose
def index(self, reload=None):
"""
Build index.html for cherrypy
Render the template and return the html file to be delivered to the browser
:return: contents of the template after beeing rendered
"""

tabcount = 2

tmpl = self.tplenv.get_template('index.html')
return tmpl.render(plugin_shortname=self.plugin.get_shortname(),
plugin_version=self.plugin.get_version(),
plugin_info=self.plugin.get_info(),
tabcount=tabcount,
p=self.plugin)
Binary file added unifi/assets/webif_unifi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unifi/assets/webif_unifi_generator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions unifi/locale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ plugin_translations:
'Letztes Update': {'de': '=', 'en': 'Last update'}
'Letzter Change': {'de': '=', 'en': 'Last change'}
'PollCycle': {'de': 'Abfragezyklus (s)', 'en': 'Poll cycle (s)'}


'Probleme': {'de': '=', 'en': 'Issues'}
'Keine': {'de': '=', 'en': 'None'}
2 changes: 1 addition & 1 deletion unifi/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugin:
# documentation: https://github.com/smarthomeNG/smarthome/wiki/CLI-Plugin # url of documentation (wiki) page
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1278068-unifi-controller-api-wlan

version: 1.6.2 # Plugin version
version: 1.6.3 # Plugin version
sh_minversion: 1.9.0 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
multi_instance: False # plugin supports multi instance
Expand Down
Loading

0 comments on commit 9b057f4

Please sign in to comment.