From 36e2a78fb173df7792b988fa4c200e66933cda61 Mon Sep 17 00:00:00 2001 From: Felix Kaechele Date: Sat, 21 Oct 2023 19:03:48 -0400 Subject: [PATCH] fix: ensure a minimum flame height value of 1 for any non-zero brightness value from the entity See https://community.home-assistant.io/t/napoleon-efire-enabled-fireplaces-work-in-progress/547976/31 Signed-off-by: Felix Kaechele --- custom_components/napoleon_efire/light.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/napoleon_efire/light.py b/custom_components/napoleon_efire/light.py index b21f1fe..6bd6ccc 100644 --- a/custom_components/napoleon_efire/light.py +++ b/custom_components/napoleon_efire/light.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from math import ceil from typing import Any from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity @@ -63,7 +64,7 @@ async def async_turn_on(self, **kwargs: Any) -> None: """Instruct the flame to turn on.""" flame_height = 6 if ATTR_BRIGHTNESS in kwargs: - flame_height = round(kwargs[ATTR_BRIGHTNESS] / 255 * 6) + flame_height = min(ceil(kwargs[ATTR_BRIGHTNESS] / 255 * 6), 6) # Setting the flame height to a non-zero value will also implicitly # call the power_on function in the bonaparte library. # Therefor, not calling it explicitly here.