Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ Tested Devices
* `FRITZ!DECT 500`_
* `Comet DECT`_
* `Panasonic KX-HNS101`
* `Magenta SmartHome Zwischenstecker außen`_
* `Magenta SmartHome Zwischenstecker innen`
* `Magenta Smarthome Tür-/Fensterkontakt optisch`_
* `Magenta Smarthome Tür-/Fensterkontakt magnetisch`_
* `RADEMACHER RolloTron DECT 1213`_


Expand Down Expand Up @@ -116,5 +119,7 @@ References
.. _FRITZ!DECT 440: https://avm.de/produkte/fritzdect/fritzdect-440/
.. _FRITZ!DECT 500: https://avm.de/produkte/fritzdect/fritzdect-500/
.. _FRITZ!Box 6490 Cable: https://avm.de/produkte/fritzbox/fritzbox-6490-cable/
.. _Magenta SmartHome Zwischenstecker außen: https://www.smarthome.de/geraete/smarthome-zwischenstecker-aussen-schwarz
.. _Magenta Smarthome Tür-/Fensterkontakt optisch: https://www.smarthome.de/geraete/smarthome-tuer-fensterkontakt-optisch-weiss
.. _Magenta Smarthome Tür-/Fensterkontakt magnetisch: https://www.smarthome.de/geraete/smarthome-tuer-fensterkontakt-magnetisch-weiss
.. _RADEMACHER RolloTron DECT 1213: https://www.rademacher.de/shop/rollladen-sonnenschutz/elektrischer-gurtwickler/rollotron-dect-1213
2 changes: 1 addition & 1 deletion pyfritzhome/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def list_all(fritz, args):
if device.has_switch:
print(" Switch:")
print(" switch_state=%s" % device.switch_state)
if device.has_switch:
if device.has_powermeter:
print(" Powermeter:")
print(" power=%s" % device.power)
print(" energy=%s" % device.energy)
Expand Down
79 changes: 54 additions & 25 deletions pyfritzhome/devicetypes/fritzhomedeviceswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FritzhomeDeviceSwitch(FritzhomeDeviceBase):
switch_state = None
switch_mode = None
lock = None
simple_switch = None

def _update_from_node(self, node):
super()._update_from_node(node)
Expand All @@ -28,38 +29,66 @@ def _update_from_node(self, node):
@property
def has_switch(self):
"""Check if the device has switch function."""
return self._has_feature(FritzhomeDeviceFeatures.SWITCH)
self.simple_switch = not self._has_feature(FritzhomeDeviceFeatures.SWITCH)
self.simple_switch = self.simple_switch and self._has_feature(FritzhomeDeviceFeatures.SWITCHABLE)
return (self._has_feature(FritzhomeDeviceFeatures.SWITCH) or self.simple_switch)

def _update_switch_from_node(self, node):
val = node.find("switch")
try:
self.switch_state = self.get_node_value_as_int_as_bool(val, "state")
except Exception:
self.switch_state = None
self.switch_mode = self.get_node_value(val, "mode")
try:
self.lock = self.get_node_value_as_int_as_bool(val, "lock")
except Exception:
self.lock = None

# optional value
try:
self.device_lock = self.get_node_value_as_int_as_bool(val, "devicelock")
except Exception:
pass
if not self.simple_switch :

val = node.find("switch")
try:
self.switch_state = self.get_node_value_as_int_as_bool(val, "state")
except Exception:
self.switch_state = None
self.switch_mode = self.get_node_value(val, "mode")
try:
self.lock = self.get_node_value_as_int_as_bool(val, "lock")
except Exception:
self.lock = None

# optional value
try:
self.device_lock = self.get_node_value_as_int_as_bool(val, "devicelock")
except Exception:
pass

else :
val = node.find("simpleonoff")
try:
self.switch_state = self.get_node_value_as_int_as_bool(val, "state")
except ValueError:
pass

def get_switch_state(self):
"""Get the switch state."""
return self._fritz.get_switch_state(self.ain)
if not self.simple_switch :
"""Get the switch state."""
return self._fritz.get_switch_state(self.ain)
else :
return self.switch_state

def set_switch_state_on(self):
"""Set the switch state to on."""
return self._fritz.set_switch_state_on(self.ain)
if not self.simple_switch :
"""Set the switch state to on."""
return self._fritz.set_switch_state_on(self.ain)
else :
self.switch_state = True
self._fritz.set_state_on(self.ain)


def set_switch_state_off(self):
"""Set the switch state to off."""
return self._fritz.set_switch_state_off(self.ain)
if not self.simple_switch :
"""Set the switch state to off."""
return self._fritz.set_switch_state_off(self.ain)
else :
self.switch_state = True
self._fritz.set_state_off(self.ain)

def set_switch_state_toggle(self):
"""Toggle the switch state."""
return self._fritz.set_switch_state_toggle(self.ain)
if not self.simple_switch :
"""Toggle the switch state."""
return self._fritz.set_switch_state_toggle(self.ain)
else :
self.switch_state = True
self._fritz.set_state_toggle(self.ain)