From 5ecb246effc0bd12084aca0c87bca34ab70b4537 Mon Sep 17 00:00:00 2001 From: andvikt Date: Fri, 29 Oct 2021 19:52:10 +0300 Subject: [PATCH] fix brightness --- custom_components/mega/entities.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/custom_components/mega/entities.py b/custom_components/mega/entities.py index fce250b..75a37ac 100644 --- a/custom_components/mega/entities.py +++ b/custom_components/mega/entities.py @@ -430,6 +430,8 @@ class MegaOutPort(MegaPushEntity): )) def _calc_brightness(self, brightness): + if brightness is None: + brightness = 0 pct = brightness / 255 pct = max((0, pct)) pct = min((pct, 1)) @@ -439,6 +441,8 @@ class MegaOutPort(MegaPushEntity): return brightness def _cal_reverse_brightness(self, brightness): + if brightness is None: + brightness = 0 l, h = self.range d = h - l pct = (brightness - l) / d