1 # Written by Ingar Arntzen, Norut
2 # see LICENSE.txt for license information
4 """This module implements a SwitchPower UPnP Server."""
7 from BaseLib.UPnP.upnpserver import UPnPService
9 ##############################################
10 # SWITCH POWER SERVICE
11 ##############################################
13 class SwitchPower(UPnPService):
15 """This class implements a simple SwitchPower service.
16 The supported actions essentially allow clients to switch power
17 on and off on a virtual device."""
19 def __init__(self, service_id):
20 UPnPService.__init__(self, service_id, 'SwitchPower',
22 boolean = types.BooleanType
24 # Define EventVariables
25 self._status = self.define_evented_variable("Status",
29 self.define_action(self.get_status,
30 out_args=[("ResultStatus", boolean )],
32 self.define_action(self.get_target,
33 out_args=[("RetTargetValue", boolean)],
35 self.define_action(self.set_target,
36 in_args=[("NewTargetValue", boolean)],
43 """Get the power status of the switch."""
44 self.log("GetStatus %s" % self._status.get())
45 return self._status.get()
48 """Get the target power status for the switch."""
49 self.log("GetTarget %s" % self._target)
52 def set_target(self, new_value):
53 """Set the target power status for the switch.
54 This also sets the status similarly at some point (immediately)."""
55 self.log("SetTarget %s" % new_value)
56 self._target = new_value
57 # Could delay this one
58 self._status.set(new_value)