mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Add mill number platform (#134044)
* Mill number, max heating power Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * Mill number, max heating power Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * Mill number, max heating power Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * Mill number, max heating power Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * Mill number, max heating power Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> * type Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> --------- Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
parent
97dc72a6e2
commit
5e981d00a4
@ -16,7 +16,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
|
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
|
||||||
from .coordinator import MillDataUpdateCoordinator
|
from .coordinator import MillDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
PLATFORMS = [Platform.CLIMATE, Platform.NUMBER, Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
83
homeassistant/components/mill/number.py
Normal file
83
homeassistant/components/mill/number.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
"""Support for mill wifi-enabled home heaters."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from mill import MillDevice
|
||||||
|
|
||||||
|
from homeassistant.components.number import NumberDeviceClass, NumberEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_USERNAME, UnitOfPower
|
||||||
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, MANUFACTURER
|
||||||
|
from .coordinator import MillDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
) -> None:
|
||||||
|
"""Set up the Mill Number."""
|
||||||
|
if entry.data.get(CONNECTION_TYPE) == CLOUD:
|
||||||
|
mill_data_coordinator: MillDataUpdateCoordinator = hass.data[DOMAIN][CLOUD][
|
||||||
|
entry.data[CONF_USERNAME]
|
||||||
|
]
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
MillNumber(mill_data_coordinator, mill_device)
|
||||||
|
for mill_device in mill_data_coordinator.data.values()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MillNumber(CoordinatorEntity[MillDataUpdateCoordinator], NumberEntity):
|
||||||
|
"""Representation of a Mill number device."""
|
||||||
|
|
||||||
|
_attr_device_class = NumberDeviceClass.POWER
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_native_max_value = 2000
|
||||||
|
_attr_native_min_value = 0
|
||||||
|
_attr_native_step = 1
|
||||||
|
_attr_native_unit_of_measurement = UnitOfPower.WATT
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: MillDataUpdateCoordinator,
|
||||||
|
mill_device: MillDevice,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the number."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
|
||||||
|
self._id = mill_device.device_id
|
||||||
|
self._available = False
|
||||||
|
self._attr_unique_id = f"{mill_device.device_id}_max_heating_power"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, mill_device.device_id)},
|
||||||
|
name=mill_device.name,
|
||||||
|
manufacturer=MANUFACTURER,
|
||||||
|
model=mill_device.model,
|
||||||
|
)
|
||||||
|
self._update_attr(mill_device)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
"""Handle updated data from the coordinator."""
|
||||||
|
self._update_attr(self.coordinator.data[self._id])
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _update_attr(self, device: MillDevice) -> None:
|
||||||
|
self._attr_native_value = device.data["deviceSettings"]["reported"].get(
|
||||||
|
"max_heater_power"
|
||||||
|
)
|
||||||
|
self._available = device.available and self._attr_native_value is not None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return super().available and self._available
|
||||||
|
|
||||||
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
|
"""Set new value."""
|
||||||
|
await self.coordinator.mill_data_connection.max_heating_power(self._id, value)
|
@ -147,5 +147,5 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
|
||||||
assert unload_entry.call_count == 2
|
assert unload_entry.call_count == 3
|
||||||
assert entry.entry_id not in hass.data[mill.DOMAIN]
|
assert entry.entry_id not in hass.data[mill.DOMAIN]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user