Repository: hthiery/python-fritzhome

Issue:
Powermeter values can be empty
There are new powermeter devices that can return empty/invalid values in some situations. To avoid throwing an exception and let the lib crash we should catch this for `power` and `energy` values.

Discussion:

Solution patch:
diff --git a/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py b/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py
index 237070c..a4e651a 100644
--- a/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py
+++ b/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py
@@ -34,8 +34,17 @@ class FritzhomeDevicePowermeter(FritzhomeDeviceBase):
     def _update_powermeter_from_node(self, node):
         _LOGGER.debug("update powermeter device")
         val = node.find("powermeter")
-        self.power = int(val.findtext("power"))
-        self.energy = int(val.findtext("energy"))
+
+        try:
+            self.power = int(val.findtext("power"))
+        except Exception:
+            pass
+
+        try:
+            self.energy = int(val.findtext("energy"))
+        except Exception:
+            pass
+
         try:
             self.voltage = int(val.findtext("voltage"))
         except Exception:


Test patch:
diff --git a/tests/responses/powermeter/device_list_faulty.xml b/tests/responses/powermeter/device_list_faulty.xml
index 925f747..1de8268 100644
--- a/tests/responses/powermeter/device_list_faulty.xml
+++ b/tests/responses/powermeter/device_list_faulty.xml
@@ -10,13 +10,10 @@
             <devicelock>0</devicelock>
         </switch>
         <powermeter>
-            <power>0</power>
-            <energy>0</energy>
-            <voltage>0</voltage>
         </powermeter>
         <temperature>
             <celsius>285</celsius>
             <offset>0</offset>
         </temperature>
     </device>
-</devicelist>
\ No newline at end of file
+</devicelist>
diff --git a/tests/test_fritzhomedevicepowermeter.py b/tests/test_fritzhomedevicepowermeter.py
index 1d568b7..026b601 100644
--- a/tests/test_fritzhomedevicepowermeter.py
+++ b/tests/test_fritzhomedevicepowermeter.py
@@ -74,7 +74,7 @@ class TestFritzhomeDevicePowermeter(object):
         self.fritz.update_devices()
         device = self.fritz.get_device_by_ain("08761 0000434")
 
-        assert device.energy == 0
-        assert device.power == 0
-        assert device.voltage == 0
+        assert device.energy is None
+        assert device.power is None
+        assert device.voltage is None
         assert device.current is None