From e1985441de15e25dd8e64d6a3555539db724dfd4 Mon Sep 17 00:00:00 2001 From: sqozz Date: Mon, 20 Jan 2020 21:29:20 +0100 Subject: [PATCH] Fix ZeroDivisionError if plug is powered off --- sem6000.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sem6000.py b/sem6000.py index 51a0d86..df90f0a 100644 --- a/sem6000.py +++ b/sem6000.py @@ -208,7 +208,10 @@ class SEMSocket(): self.__btle_device.total_power = total_power # calculated values - self.__btle_device.power_factor = power / (voltage * current) + try: + self.__btle_device.power_factor = power / (voltage * current) + except ZeroDivisionError: + self.__btle_device.power_factor = None elif message_type == 0x17: if data[5] == 0x00 or data[5] == 0x01: if data[4]: