1 """Support for mill wifi-enabled home heaters."""
3 from __future__
import annotations
10 SensorEntityDescription,
15 CONCENTRATION_PARTS_PER_BILLION,
16 CONCENTRATION_PARTS_PER_MILLION,
45 HEATER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
48 translation_key=
"year_consumption",
49 device_class=SensorDeviceClass.ENERGY,
50 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
51 state_class=SensorStateClass.TOTAL_INCREASING,
54 key=CONSUMPTION_TODAY,
55 translation_key=
"day_consumption",
56 device_class=SensorDeviceClass.ENERGY,
57 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
58 state_class=SensorStateClass.TOTAL_INCREASING,
62 translation_key=
"current_power",
63 device_class=SensorDeviceClass.POWER,
64 native_unit_of_measurement=UnitOfPower.WATT,
65 state_class=SensorStateClass.MEASUREMENT,
69 translation_key=
"control_signal",
70 native_unit_of_measurement=PERCENTAGE,
71 state_class=SensorStateClass.MEASUREMENT,
75 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
78 device_class=SensorDeviceClass.TEMPERATURE,
79 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
80 state_class=SensorStateClass.MEASUREMENT,
84 device_class=SensorDeviceClass.HUMIDITY,
85 native_unit_of_measurement=PERCENTAGE,
86 state_class=SensorStateClass.MEASUREMENT,
90 device_class=SensorDeviceClass.BATTERY,
91 native_unit_of_measurement=PERCENTAGE,
92 state_class=SensorStateClass.MEASUREMENT,
93 entity_category=EntityCategory.DIAGNOSTIC,
97 device_class=SensorDeviceClass.CO2,
98 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
99 translation_key=
"estimated_co2",
100 state_class=SensorStateClass.MEASUREMENT,
104 native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
105 translation_key=
"tvoc",
106 state_class=SensorStateClass.MEASUREMENT,
110 LOCAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
112 key=
"control_signal",
113 translation_key=
"control_signal",
114 native_unit_of_measurement=PERCENTAGE,
115 state_class=SensorStateClass.MEASUREMENT,
119 translation_key=
"current_power",
120 device_class=SensorDeviceClass.POWER,
121 native_unit_of_measurement=UnitOfPower.WATT,
122 state_class=SensorStateClass.MEASUREMENT,
125 key=
"raw_ambient_temperature",
126 translation_key=
"uncalibrated_temperature",
127 device_class=SensorDeviceClass.TEMPERATURE,
128 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
129 state_class=SensorStateClass.MEASUREMENT,
130 entity_registry_enabled_default=
False,
134 SOCKET_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
137 device_class=SensorDeviceClass.HUMIDITY,
138 native_unit_of_measurement=PERCENTAGE,
139 state_class=SensorStateClass.MEASUREMENT,
141 *HEATER_SENSOR_TYPES,
146 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
148 """Set up the Mill sensor."""
149 if entry.data.get(CONNECTION_TYPE) == LOCAL:
150 mill_data_coordinator = hass.data[DOMAIN][LOCAL][entry.data[CONF_IP_ADDRESS]]
154 mill_data_coordinator,
157 for entity_description
in LOCAL_SENSOR_TYPES
161 mill_data_coordinator = hass.data[DOMAIN][CLOUD][entry.data[CONF_USERNAME]]
165 mill_data_coordinator,
169 for mill_device
in mill_data_coordinator.data.values()
170 for entity_description
in (
172 if isinstance(mill_device, mill.Socket)
173 else HEATER_SENSOR_TYPES
174 if isinstance(mill_device, mill.Heater)
183 """Representation of a Mill Sensor device."""
185 _attr_has_entity_name =
True
187 def __init__(self, coordinator, entity_description, mill_device):
188 """Initialize the sensor."""
191 self.
_id_id = mill_device.device_id
194 self.
_attr_unique_id_attr_unique_id = f
"{mill_device.device_id}_{entity_description.key}"
196 identifiers={(DOMAIN, mill_device.device_id)},
197 name=mill_device.name,
198 manufacturer=MANUFACTURER,
199 model=mill_device.model,
205 """Handle updated data from the coordinator."""
211 """Return True if entity is available."""
212 return super().available
and self.
_available_available
221 """Representation of a Mill Sensor device."""
223 _attr_has_entity_name =
True
225 def __init__(self, coordinator, entity_description):
226 """Initialize the sensor."""
230 if mac := coordinator.mill_data_connection.mac_address:
233 connections={(CONNECTION_NETWORK_MAC, mac)},
234 configuration_url=self.coordinator.mill_data_connection.url,
235 manufacturer=MANUFACTURER,
236 model=
"Generation 3",
237 name=coordinator.mill_data_connection.name,
238 sw_version=coordinator.mill_data_connection.version,
243 """Return the native value of the sensor."""
def __init__(self, coordinator, entity_description)
def __init__(self, coordinator, entity_description, mill_device)
def _update_attr(self, device)
None _handle_coordinator_update(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)