Fix bugs
This commit is contained in:
37
plugin.py
37
plugin.py
@@ -4,15 +4,15 @@
|
||||
#
|
||||
#pylint: disable=line-too-long
|
||||
"""
|
||||
<plugin key="Auroras.live" name="Auroras Forecast" author="fjumelle" version="1.0.0" wikilink="" externallink="">
|
||||
<plugin key="Auroras" name="Auroras" author="fjumelle" version="1.0.0" wikilink="" externallink="">
|
||||
<description>
|
||||
<h2>Auroras Forecast</h2><br/>
|
||||
Powered by Auroras.live.<br/>
|
||||
<h2>Auroras</h2><br/>
|
||||
Powered by Auroras.live
|
||||
</description>
|
||||
<params>
|
||||
<param field="Mode1" label="Latitude" width="40px" required="true" default="45.0"/>
|
||||
<param field="Mode2" label="Longitude" width="40px" required="true" default="3.0"/>
|
||||
<param field="Mode5" label="Polling interval (min)" width="40px" required="true" default="60"/>
|
||||
<param field="Mode1" label="Latitude" width="100px" default="45"/>
|
||||
<param field="Mode2" label="Longitude" width="100px" default="5"/>
|
||||
<param field="Mode5" label="Pooling (min)" width="200px" default="60"/>
|
||||
<param field="Mode6" label="Logging Level" width="200px">
|
||||
<options>
|
||||
<option label="Normal" value="0" default="true"/>
|
||||
@@ -49,28 +49,24 @@ class BasePlugin(object):
|
||||
# See https://www.domoticz.com/wiki/Developing_a_Python_plugin#Available_Device_Types
|
||||
# Unit, Name, Type, Subtype, Switchtype, Options, Icon, Used
|
||||
_UNIT_BZ: ["Bz", 243, 31, 0, {"Custom": "0;nt Bz"}, None, 1,],
|
||||
_UNIT_DENSITY: ["Density", 243,316, 0, {"Custom": "0;p/cm3"}, None, 1,],
|
||||
_UNIT_DENSITY: ["Density", 243,31, 0, {"Custom": "0;p/cm3"}, None, 1,],
|
||||
_UNIT_SPEED: ["Speed", 243, 31, 0, {"Custom": "0;km/s"}, None, 1,],
|
||||
_UNIT_KP: ["KP", 243, 31, 0, None, None, 1],
|
||||
_UNIT_LOCAL_VALUE: ["Local Value", 243, 6, 0, None, None, 1],
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.debug = False
|
||||
self.pooling = 30
|
||||
self.pooling_steps = 1
|
||||
self.pooling_current_step = 1
|
||||
self.devices = []
|
||||
self._pooling = 30
|
||||
self._pooling_steps = 1
|
||||
self._pooling_current_step = 1
|
||||
|
||||
def on_start(self):
|
||||
"""At statup"""
|
||||
# setup the appropriate logging level
|
||||
debuglevel = int(Parameters["Mode6"])
|
||||
if debuglevel != 0:
|
||||
self.debug = True
|
||||
Domoticz.Debugging(debuglevel)
|
||||
else:
|
||||
self.debug = False
|
||||
Domoticz.Debugging(0)
|
||||
|
||||
# Polling interval = X sec
|
||||
@@ -78,9 +74,10 @@ class BasePlugin(object):
|
||||
pooling = int(Parameters["Mode5"])*60
|
||||
except ValueError:
|
||||
pooling = self._DEFAULT_POOLING
|
||||
self.pooling_steps = math.ceil(pooling/30)
|
||||
self.pooling = pooling // self.pooling_steps
|
||||
Domoticz.Heartbeat(self.pooling)
|
||||
self._pooling_steps = math.ceil(pooling/30)
|
||||
self._pooling_current_step = self._pooling_steps #To heartbeat at the first beat
|
||||
self._pooling = pooling // self._pooling_steps
|
||||
Domoticz.Heartbeat(self._pooling)
|
||||
|
||||
# Create devices
|
||||
for u, unit in self._UNITS.items():
|
||||
@@ -113,7 +110,7 @@ class BasePlugin(object):
|
||||
|
||||
def on_heartbeat(self):
|
||||
"""Time to heartbeat :)"""
|
||||
if self.pooling_current_step == self.pooling_steps:
|
||||
if self._pooling_current_step >= self._pooling_steps:
|
||||
query = {
|
||||
'lat': Parameters["Mode1"],
|
||||
'long': Parameters["Mode2"],
|
||||
@@ -148,9 +145,9 @@ class BasePlugin(object):
|
||||
except requests.exceptions.RetryError as exc:
|
||||
Domoticz.Error(str(exc))
|
||||
|
||||
self.pooling_current_step = 1
|
||||
self._pooling_current_step = 1
|
||||
else:
|
||||
self.pooling_current_step = self.pooling_current_step + 1
|
||||
self._pooling_current_step = self._pooling_current_step + 1
|
||||
|
||||
|
||||
_plugin = BasePlugin()
|
||||
|
||||
Reference in New Issue
Block a user