mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Add sensors to Mill local heaters (#61247)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
54e312e1f7
commit
4c542336d5
@ -12,9 +12,11 @@ from homeassistant.components.sensor import (
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONCENTRATION_PARTS_PER_BILLION,
|
CONCENTRATION_PARTS_PER_BILLION,
|
||||||
CONCENTRATION_PARTS_PER_MILLION,
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
|
CONF_IP_ADDRESS,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
ENERGY_KILO_WATT_HOUR,
|
ENERGY_KILO_WATT_HOUR,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
|
POWER_WATT,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -90,10 +92,43 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
LOCAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="control_signal",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
name="Control signal",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="current_power",
|
||||||
|
device_class=SensorDeviceClass.POWER,
|
||||||
|
native_unit_of_measurement=POWER_WATT,
|
||||||
|
name="Current power",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="raw_ambient_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
|
name="Uncalibrated temperature",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
"""Set up the Mill sensor."""
|
"""Set up the Mill sensor."""
|
||||||
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
||||||
|
mill_data_coordinator = hass.data[DOMAIN][LOCAL][entry.data[CONF_IP_ADDRESS]]
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
LocalMillSensor(
|
||||||
|
mill_data_coordinator,
|
||||||
|
entity_description,
|
||||||
|
)
|
||||||
|
for entity_description in LOCAL_SENSOR_TYPES
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
mill_data_coordinator = hass.data[DOMAIN][CLOUD][entry.data[CONF_USERNAME]]
|
mill_data_coordinator = hass.data[DOMAIN][CLOUD][entry.data[CONF_USERNAME]]
|
||||||
@ -154,3 +189,27 @@ class MillSensor(CoordinatorEntity, SensorEntity):
|
|||||||
def _update_attr(self, device):
|
def _update_attr(self, device):
|
||||||
self._available = device.available
|
self._available = device.available
|
||||||
self._attr_native_value = getattr(device, self.entity_description.key)
|
self._attr_native_value = getattr(device, self.entity_description.key)
|
||||||
|
|
||||||
|
|
||||||
|
class LocalMillSensor(CoordinatorEntity, SensorEntity):
|
||||||
|
"""Representation of a Mill Sensor device."""
|
||||||
|
|
||||||
|
def __init__(self, coordinator, entity_description):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
|
||||||
|
self.entity_description = entity_description
|
||||||
|
self._attr_name = (
|
||||||
|
f"{coordinator.mill_data_connection.name} {entity_description.name}"
|
||||||
|
)
|
||||||
|
self._update_attr()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
"""Handle updated data from the coordinator."""
|
||||||
|
self._update_attr()
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _update_attr(self) -> None:
|
||||||
|
self._attr_native_value = self.coordinator.data[self.entity_description.key]
|
||||||
|
@ -78,6 +78,8 @@ async def test_setup_with_local_config(hass):
|
|||||||
"ambient_temperature": 20,
|
"ambient_temperature": 20,
|
||||||
"set_temperature": 22,
|
"set_temperature": 22,
|
||||||
"current_power": 0,
|
"current_power": 0,
|
||||||
|
"control_signal": 0,
|
||||||
|
"raw_ambient_temperature": 19,
|
||||||
},
|
},
|
||||||
) as mock_fetch, patch(
|
) as mock_fetch, patch(
|
||||||
"mill_local.Mill.connect",
|
"mill_local.Mill.connect",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user