Skip to content

Commit 5e981d0

Browse files
Add mill number platform (home-assistant#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>
1 parent 97dc72a commit 5e981d0

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

homeassistant/components/mill/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, LOCAL
1717
from .coordinator import MillDataUpdateCoordinator
1818

19-
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
19+
PLATFORMS = [Platform.CLIMATE, Platform.NUMBER, Platform.SENSOR]
2020

2121

2222
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""Support for mill wifi-enabled home heaters."""
2+
3+
from __future__ import annotations
4+
5+
from mill import MillDevice
6+
7+
from homeassistant.components.number import NumberDeviceClass, NumberEntity
8+
from homeassistant.config_entries import ConfigEntry
9+
from homeassistant.const import CONF_USERNAME, UnitOfPower
10+
from homeassistant.core import HomeAssistant, callback
11+
from homeassistant.helpers.device_registry import DeviceInfo
12+
from homeassistant.helpers.entity_platform import AddEntitiesCallback
13+
from homeassistant.helpers.update_coordinator import CoordinatorEntity
14+
15+
from .const import CLOUD, CONNECTION_TYPE, DOMAIN, MANUFACTURER
16+
from .coordinator import MillDataUpdateCoordinator
17+
18+
19+
async def async_setup_entry(
20+
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
21+
) -> None:
22+
"""Set up the Mill Number."""
23+
if entry.data.get(CONNECTION_TYPE) == CLOUD:
24+
mill_data_coordinator: MillDataUpdateCoordinator = hass.data[DOMAIN][CLOUD][
25+
entry.data[CONF_USERNAME]
26+
]
27+
28+
async_add_entities(
29+
MillNumber(mill_data_coordinator, mill_device)
30+
for mill_device in mill_data_coordinator.data.values()
31+
)
32+
33+
34+
class MillNumber(CoordinatorEntity[MillDataUpdateCoordinator], NumberEntity):
35+
"""Representation of a Mill number device."""
36+
37+
_attr_device_class = NumberDeviceClass.POWER
38+
_attr_has_entity_name = True
39+
_attr_native_max_value = 2000
40+
_attr_native_min_value = 0
41+
_attr_native_step = 1
42+
_attr_native_unit_of_measurement = UnitOfPower.WATT
43+
44+
def __init__(
45+
self,
46+
coordinator: MillDataUpdateCoordinator,
47+
mill_device: MillDevice,
48+
) -> None:
49+
"""Initialize the number."""
50+
super().__init__(coordinator)
51+
52+
self._id = mill_device.device_id
53+
self._available = False
54+
self._attr_unique_id = f"{mill_device.device_id}_max_heating_power"
55+
self._attr_device_info = DeviceInfo(
56+
identifiers={(DOMAIN, mill_device.device_id)},
57+
name=mill_device.name,
58+
manufacturer=MANUFACTURER,
59+
model=mill_device.model,
60+
)
61+
self._update_attr(mill_device)
62+
63+
@callback
64+
def _handle_coordinator_update(self) -> None:
65+
"""Handle updated data from the coordinator."""
66+
self._update_attr(self.coordinator.data[self._id])
67+
self.async_write_ha_state()
68+
69+
@callback
70+
def _update_attr(self, device: MillDevice) -> None:
71+
self._attr_native_value = device.data["deviceSettings"]["reported"].get(
72+
"max_heater_power"
73+
)
74+
self._available = device.available and self._attr_native_value is not None
75+
76+
@property
77+
def available(self) -> bool:
78+
"""Return True if entity is available."""
79+
return super().available and self._available
80+
81+
async def async_set_native_value(self, value: float) -> None:
82+
"""Set new value."""
83+
await self.coordinator.mill_data_connection.max_heating_power(self._id, value)

tests/components/mill/test_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,5 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
147147

148148
assert await hass.config_entries.async_unload(entry.entry_id)
149149

150-
assert unload_entry.call_count == 2
150+
assert unload_entry.call_count == 3
151151
assert entry.entry_id not in hass.data[mill.DOMAIN]

0 commit comments

Comments
 (0)