Author: Gwadavel
Date: 2009-09-20 01:49:27 +0200 (Sun, 20 Sep 2009)
New Revision: 5450

Modified:
   
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.po
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.wiki
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.po
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.wiki
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/help.wiki
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.pot
   software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.xml
Log:
Rewrite plugin - add check, Tux alerts you when the battery state selected is 
met

Modified: 
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
        2009-09-18 14:52:16 UTC (rev 5449)
+++ 
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
        2009-09-19 23:49:27 UTC (rev 5450)
@@ -40,88 +40,33 @@
 from util.SimplePlugin.SimplePluginConfiguration import 
SimplePluginConfiguration
 from util.SimplePlugin.SimplePlugin import SimplePlugin
 
-class Battery(object):
+
+class Configuration(SimplePluginConfiguration):
+    """This class make an access to the plugin parameters.
+    Parameters are automatically filled by the SimplePlugin class at plugin
+    starting.
     """
-    Manage the battery.
-    """
-   
-    def __init__(self, plug):
-        '''
-        '''
-        self.tgp_language = "en"
-        self.tgp_ip = "127.0.0.1"
-        self.tgp_port = 270        
 
-        self.plugin = plug 
-
-        # Test language, ip, port
-        if "tgp_language" in os.environ:
-            self.tgp_language = os.environ["tgp_language"]
-
-        if "tgp_ip" in os.environ:
-            self.tgp_ip = os.environ["tgp_ip"]
-
-        if "tgp_port" in os.environ:
-            self.tgp_port = int(os.environ["tgp_port"])
-
-        self.tux = TuxAPI(self.tgp_ip, self.tgp_port)
-
-        if self.tux.server.connect(CLIENT_LEVEL_RESTRICTED, 'batterylevel', 
'plugin-battery'):
-            self.tux.server.disconnect()
-        else:
-            self.tgp_port = 54321
-            self.tux = TuxAPI(self.tgp_ip, self.tgp_port)     
-        
-    def tuxConnect(self):
-        '''
-        Wait connected
-        '''
-        self.tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'batterylevel', 
'plugin-battery')
-        self.tux.server.waitConnected(5.0)
-        self.tux.dongle.waitConnected(5.0)
-        self.tux.radio.waitConnected(5.0)
-        return self.tux.access.waitAcquire(5.0, ACCESS_PRIORITY_NORMAL)
-
-
-    def getLevel(self):
+    def __init__(self):
+        """Initialization of the class.
+        It's necessary to initialize the values because the type of the python
+        variables is set by value assignation. If we don't initialize the
+        parameters the simple plugin class can't check and validate the values
+        passed by the plugins server through the os environment variables.
         """
-        Return Battery Level
-        """
+        # Call the super class
+        SimplePluginConfiguration.__init__(self)
+        # Initialize the parameters
+        self.__checkState = ""
 
-        return self.tux.battery.getLevel()
- 
+    def getCheckState(self):
+        return self.__checkState
 
-    def getState(self):
-        """
-        Return Battery State
-        """
- 
-        return self.tux.battery.getState()
+    def setCheckState(self, checkState):
+        self.__checkState = checkState
 
 
-    def start(self):
-        """
-        """
 
-        if self.tuxConnect():
-
-            if not self.tux.radio.getConnected():
-                plugin.throwTrace("I can't find my fish. Please, make sure I'm 
connected.")
-            else:
-                plugin.throwMessage("The battery level is {0}", 
"%1.2f"%self.getLevel())               
-                plugin.throwMessage("The battery state is {0}", 
self.getState())
-        self.stop()
-
-
-    def stop(self):
-        """
-        """
-
-        self.tux.access.release()
-        self.tux.server.disconnect()
-        self.tux.destroy()
- 
-
 class BatteryPlugin(SimplePlugin):
     """This class override the SimplePlugin class to make easy
     the plugin coding.
@@ -132,26 +77,95 @@
         """
         # Call the super class
         SimplePlugin.__init__(self)
-        self.sbattery = Battery(self)
+        self.__tgp_ip = "127.0.0.1"
+        self.__tgp_port = 270        
+        # Test language, ip, port
+        if "tgp_ip" in os.environ:
+            self.__tgp_ip = os.environ["tgp_ip"]
+
+        if "tgp_port" in os.environ:
+            self.__tgp_port = int(os.environ["tgp_port"])
+
+        self.__tux = TuxAPI(self.__tgp_ip, self.__tgp_port)
+
+        if self.__tux.server.connect(CLIENT_LEVEL_RESTRICTED, 'batterylevel', 
'plugin-battery'):
+            self.__tux.server.disconnect()
+        else:
+            self.__tgp_port = 54321
+            self.__tux = TuxAPI(self.__tgp_ip, self.__tgp_port)     
         
 
     def start(self):
         """Plugin entry point.
         This method should be used to dispatch commands.
         """
-        self.run()
+        if self.getCommand() == "run":
+            self.run()
+        elif self.getCommand() == "check":
+            self.check()
+        else:
+            self.run()
 
     def run(self):
         """Plugin entry point for the "run" command.
         """
-        self.sbattery.start()
+        if self.__tuxConnect():
+            if not self.__tux.radio.getConnected():
+                self.throwTrace("I can't find my fish. Please, make sure I'm 
connected.")
+            else:
+                self.throwMessage("The battery level is {0}", 
"%1.2f"%self.__getLevel())               
+                self.throwMessage("The battery state is {0}", 
self.__getState())
 
+    def check(self):
+        """Plugin entry point for the "check" command.
+        """
+        if self.__tuxConnect():
+            if not self.__tux.radio.getConnected():
+                self.throwTrace("I can't find my fish. Please, make sure I'm 
connected.")
+            else:
+                # Check a condition ...
+                checkResult = self.configuration().getCheckState() == 
self.__getState()
+                # Return the check result
+                self.throwResult(checkResult)
+                if checkResult:
+                    self.throwMessage("Alert the battery state is {0}", 
self.__getState())
+
     def onPluginStop(self):
         """Callback on plugin stop.
         """
-        # Stop the fake daemon loop
-        self.sbattery.stop()
+        self.__stop()
+
+    def __tuxConnect(self):
+        '''
+        Wait connected
+        '''
+        self.__tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'batterylevel', 
'plugin-battery')
+        self.__tux.server.waitConnected(5.0)
+        self.__tux.dongle.waitConnected(5.0)
+        self.__tux.radio.waitConnected(5.0)
+        return self.__tux.access.waitAcquire(5.0, ACCESS_PRIORITY_NORMAL)
+
+    def __getLevel(self):
+        """
+        Return Battery Level
+        """
+        return self.__tux.battery.getLevel()
+ 
+
+    def __getState(self):
+        """
+        Return Battery State
+        """
+        return self.__tux.battery.getState()
+
+    def __stop(self):
+        """
+        """
+        self.__tux.access.release()
+        self.__tux.server.disconnect()
+        self.__tux.destroy()
+
         
 if __name__ == "__main__":
     plugin = BatteryPlugin()
-    plugin.boot(sys.argv[1:], SimplePluginConfiguration())
+    plugin.boot(sys.argv[1:], Configuration())

Modified: software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.po
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.po      
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.po      
2009-09-19 23:49:27 UTC (rev 5450)
@@ -1,11 +1,11 @@
-msgid "Battery Level"
-msgstr "Battery Level"
+msgid "Battery"
+msgstr "Battery"
 
-msgid "Says battery level"
-msgstr "Says battery level"
+msgid "Said battery state"
+msgstr "Said battery state"
 
-msgid "Says the battery level and it state"
-msgstr "Says the battery level and it state"
+msgid "Said the battery level and it state"
+msgstr "Said the battery level and it state"
 
 msgid "The battery level is {0}"
 msgstr "The battery level is {0}"
@@ -24,3 +24,15 @@
 
 msgid "FULL"
 msgstr "full"
+
+msgid "State to check"
+msgstr "State to check"
+
+msgid "Check battery state every x minutes"
+msgstr "Check battery state every x minutes"
+
+msgid "Alert the battery state is {0}"
+msgstr "Alert the battery state is {0}"
+
+msgid "My checker"
+msgstr "My checker"

Modified: 
software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.wiki
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.wiki    
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/en.wiki    
2009-09-19 23:49:27 UTC (rev 5450)
@@ -1,2 +1,18 @@
 == Synopsis ==
-Tux Droid says the battery level and it state
+
+Tux Droid said the battery level and it state or check a selected state.
+
+
+== Live with Tux ==
+
+Tux Droid said the battery level and it state.
+
+
+== Alert ==
+
+Tux alerts you when the battery state selected is met.
+ 
+To use "Alerts" click the Settings icon gadget and choose state to check,
+delay and click the checkbox "Check battery state every x minutes".
+
+ 

Modified: software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.po
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.po      
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.po      
2009-09-19 23:49:27 UTC (rev 5450)
@@ -1,11 +1,11 @@
-msgid "Battery Level"
-msgstr "Niveau de la batterie"
+msgid "Battery"
+msgstr "Batterie"
 
-msgid "Says battery level"
+msgid "Said battery state"
 msgstr "Indique le niveau de la batterie"
 
-msgid "Says the battery level and it state"
-msgstr "Indique le niveau de la batterie et son etat"
+msgid "Said the battery level and it state"
+msgstr "Indique le niveau de la batterie et son état"
 
 msgid "The battery level is {0}"
 msgstr "Le niveau de batterie est de {0}"
@@ -24,3 +24,15 @@
 
 msgid "FULL"
 msgstr "pleine"
+
+msgid "State to check"
+msgstr "Etat à vérifier"
+
+msgid "Check battery state every x minutes"
+msgstr "Vérifie un état de la batterie tous les x minutes"
+
+msgid "Alert the battery state is {0}"
+msgstr "Alerte la batterie est {0}"
+
+msgid "My checker"
+msgstr "Vérification"

Modified: 
software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.wiki
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.wiki    
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/fr.wiki    
2009-09-19 23:49:27 UTC (rev 5450)
@@ -1,2 +1,15 @@
-==Synopsis==
-Tux Droid donne le niveau de la batterie et son etat. 
+== Synopsis ==
+
+Tux Droid dit le niveau de la batterie et son état ou vérifie un état de la 
batterie sélectionné.
+
+== Vivre avec Tux ==
+
+Tux Droid dit le niveau de la batterie et son état.
+
+== Alertes ==
+
+Tux vous alerte quand l'état, de la batterie, sélectionné est atteint.
+
+Pour utiliser les "Alertes" cliquez sur l'icon paramètre du gadget,choisissez 
l'état, la fréquence, et cochez la case "Vérifie un état de la batterie tous 
les x minutes".
+
+

Modified: 
software_suite_v3/software/plugin/plugin-battery/trunk/resources/help.wiki
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/help.wiki  
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/help.wiki  
2009-09-19 23:49:27 UTC (rev 5450)
@@ -1,2 +1,18 @@
 == Synopsis ==
-Tux Droid says the battery level and it state
+
+Tux Droid said the battery level and it state or check a selected state.
+
+
+== Live with Tux ==
+
+Tux Droid said the battery level and it state.
+
+
+== Alert ==
+
+Tux alerts you when the battery state selected is met.
+ 
+To use "Alerts" click the Settings icon gadget and choose state to check,
+delay and click the checkbox "Check battery state every x minutes".
+
+ 

Modified: 
software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.pot
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.pot 
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.pot 
2009-09-19 23:49:27 UTC (rev 5450)
@@ -1,10 +1,10 @@
-msgid "Battery Level"
+msgid "Battery"
 msgstr ""
 
-msgid "Says battery level"
+msgid "Said battery state"
 msgstr ""
 
-msgid "Says the battery level and it state"
+msgid "Said the battery level and it state"
 msgstr ""
 
 msgid "The battery level is {0}"
@@ -24,3 +24,15 @@
 
 msgid "FULL"
 msgstr ""
+
+msgid "State to check"
+msgstr ""
+
+msgid "Check battery state every x minutes"
+msgstr ""
+
+msgid "Alert the battery state is {0}"
+msgstr ""
+
+msgid "My checker"
+msgstr ""

Modified: 
software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.xml
===================================================================
--- software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.xml 
2009-09-18 14:52:16 UTC (rev 5449)
+++ software_suite_v3/software/plugin/plugin-battery/trunk/resources/plugin.xml 
2009-09-19 23:49:27 UTC (rev 5450)
@@ -4,9 +4,9 @@
                <executable>executables/plugin-battery.py</executable>
        </interpreter>
        <description>
-               <name>Battery Level</name>
-        <ttsName>Battery Level</ttsName>
-               <description>Says battery level</description>
+               <name>Battery</name>
+        <ttsName>Battery state</ttsName>
+               <description>Said the battery level and it state</description>
                <author>Gwadavel</author>
                <version>0.0.1</version>
                <iconFile>resources/plugin.png</iconFile>
@@ -14,12 +14,43 @@
                <uuid>868a9389-01a9-4a8c-b63e-68414d154798</uuid>
         <platform>all</platform>
        </description>
+       <parameters>
+        <parameter
+                       name="checkState"
+                       description="State to check"
+                       type="enum(EMPTY,LOW,HIGH,FULL)"
+                       defaultValue="FULL"
+            platform="all"/>
+       </parameters>
        <commands>
                <command
                        name="run"
-                       description="Says the battery level and it state"
+                       description="Said the battery level and it state"
             daemon="false" />
+               <command
+                       name="check"
+                       description="Check battery state"
+            daemon="false" />
        </commands>
        <tasks>
+        <task
+            name="My checker"
+            description="Check battery state every x minutes"
+            command="check"
+            type="every x"
+            activated="false"
+
+            weekMask="true,true,true,true,true,true,true"
+            weekMaskType="weekpart"
+            weekMaskVisible="true"
+
+            hoursEnd="23:59:00"
+            hoursEndMask="true,true,false"
+            hoursEndVisible="true"
+
+            delay="00:05:00"
+            delayMask="true,true,true"
+            delayVisible="true"
+        />
     </tasks>
 </plugin>


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to