From ff2d762f55613606f48b78409bff3e829012ad85 Mon Sep 17 00:00:00 2001 From: Jeef Date: Sat, 15 Oct 2022 12:43:47 -0600 Subject: [PATCH] Intellifire - Number Entity - Flame Height Control (#79901) * Adding flame height control * oops * addressing comments * fix coverage file * addressing PR comments --- .coveragerc | 1 + .../components/intellifire/__init__.py | 1 + .../components/intellifire/number.py | 77 +++++++++++++++++++ .../components/intellifire/sensor.py | 3 +- 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/intellifire/number.py diff --git a/.coveragerc b/.coveragerc index 9b5167eb68f..ecfa407013d 100644 --- a/.coveragerc +++ b/.coveragerc @@ -582,6 +582,7 @@ omit = homeassistant/components/intellifire/coordinator.py homeassistant/components/intellifire/entity.py homeassistant/components/intellifire/fan.py + homeassistant/components/intellifire/number.py homeassistant/components/intellifire/sensor.py homeassistant/components/intellifire/switch.py homeassistant/components/intesishome/* diff --git a/homeassistant/components/intellifire/__init__.py b/homeassistant/components/intellifire/__init__.py index 020136f078c..e4e4f1a66c9 100644 --- a/homeassistant/components/intellifire/__init__.py +++ b/homeassistant/components/intellifire/__init__.py @@ -24,6 +24,7 @@ PLATFORMS = [ Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.FAN, + Platform.NUMBER, Platform.SENSOR, Platform.SWITCH, ] diff --git a/homeassistant/components/intellifire/number.py b/homeassistant/components/intellifire/number.py new file mode 100644 index 00000000000..efa567d55cb --- /dev/null +++ b/homeassistant/components/intellifire/number.py @@ -0,0 +1,77 @@ +"""Flame height number sensors.""" +from __future__ import annotations + +from dataclasses import dataclass + +from homeassistant.components.number import ( + NumberEntity, + NumberEntityDescription, + NumberMode, +) +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import DOMAIN, LOGGER +from .coordinator import IntellifireDataUpdateCoordinator +from .entity import IntellifireEntity + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up the fans.""" + coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + + description = NumberEntityDescription( + key="flame_control", + name="Flame control", + icon="mdi:arrow-expand-vertical", + ) + + async_add_entities( + [ + IntellifireFlameControlEntity( + coordinator=coordinator, description=description + ) + ] + ) + + +@dataclass +class IntellifireFlameControlEntity(IntellifireEntity, NumberEntity): + """Flame height control entity.""" + + _attr_native_max_value: float = 5 + _attr_native_min_value: float = 1 + _attr_native_step: float = 1 + _attr_mode: NumberMode = NumberMode.SLIDER + + def __init__( + self, + coordinator: IntellifireDataUpdateCoordinator, + description: NumberEntityDescription, + ) -> None: + """Initilaize Flame height Sensor.""" + super().__init__(coordinator, description) + + @property + def native_value(self) -> float | None: + """Return the current Flame Height segment number value.""" + # UI uses 1-5 for flame height, backing lib uses 0-4 + value = self.coordinator.read_api.data.flameheight + 1 + return value + + async def async_set_native_value(self, value: float) -> None: + """Slider change.""" + value_to_send: int = int(value) - 1 + LOGGER.debug( + "%s set flame height to %d with raw value %s", + self._attr_name, + value, + value_to_send, + ) + await self.coordinator.control_api.set_flame_height(height=value_to_send) + await self.coordinator.async_refresh() diff --git a/homeassistant/components/intellifire/sensor.py b/homeassistant/components/intellifire/sensor.py index 3bb3614f71e..cbd31249133 100644 --- a/homeassistant/components/intellifire/sensor.py +++ b/homeassistant/components/intellifire/sensor.py @@ -60,7 +60,8 @@ INTELLIFIRE_SENSORS: tuple[IntellifireSensorEntityDescription, ...] = ( icon="mdi:fire-circle", name="Flame Height", state_class=SensorStateClass.MEASUREMENT, - value_fn=lambda data: data.flameheight, + # UI uses 1-5 for flame height, backing lib uses 0-4 + value_fn=lambda data: (data.flameheight + 1), ), IntellifireSensorEntityDescription( key="temperature",