diff --git a/README.rst b/README.rst index 37ed83e..40cf7d0 100644 --- a/README.rst +++ b/README.rst @@ -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`_ @@ -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 diff --git a/pyfritzhome/cli.py b/pyfritzhome/cli.py index 59628ee..6672d63 100644 --- a/pyfritzhome/cli.py +++ b/pyfritzhome/cli.py @@ -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) diff --git a/pyfritzhome/devicetypes/fritzhomedeviceswitch.py b/pyfritzhome/devicetypes/fritzhomedeviceswitch.py index 66c4165..45727e6 100644 --- a/pyfritzhome/devicetypes/fritzhomedeviceswitch.py +++ b/pyfritzhome/devicetypes/fritzhomedeviceswitch.py @@ -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) @@ -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) +