Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
Daniel Hjelseth Høyer 2024-12-17 20:48:17 +01:00
parent 16b6da9c91
commit 5b7f5fef88
5 changed files with 7 additions and 63 deletions

View File

@ -14,7 +14,6 @@ from homeassistant.components.climate import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_TEMPERATURE,
CONF_IP_ADDRESS,
CONF_USERNAME,
@ -24,16 +23,12 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
from homeassistant.helpers.entity_platform import (
AddEntitiesCallback,
async_get_current_platform,
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import (
ATTR_AWAY_TEMP,
ATTR_COMFORT_TEMP,
ATTR_MAX_HEATING_POWER,
ATTR_ROOM_NAME,
ATTR_SLEEP_TEMP,
CLOUD,
@ -43,7 +38,6 @@ from .const import (
MANUFACTURER,
MAX_TEMP,
MIN_TEMP,
SERVICE_MAX_HEATING_POWER,
SERVICE_SET_ROOM_TEMP,
)
from .coordinator import MillDataUpdateCoordinator
@ -90,21 +84,6 @@ async def async_setup_entry(
DOMAIN, SERVICE_SET_ROOM_TEMP, set_room_temp, schema=SET_ROOM_TEMP_SCHEMA
)
async def max_heating_power(entity: MillHeater, service: ServiceCall) -> None:
"""Limit heating power."""
await mill_data_coordinator.mill_data_connection.max_heating_power(
entity.heater_id, service.data[ATTR_MAX_HEATING_POWER]
)
async_get_current_platform().async_register_entity_service(
SERVICE_MAX_HEATING_POWER,
schema={
vol.Required(ATTR_ENTITY_ID): cv.entity_id,
vol.Required(ATTR_MAX_HEATING_POWER): vol.Range(min=0, max=2000),
},
func=max_heating_power,
)
class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
"""Representation of a Mill Thermostat device."""
@ -131,7 +110,7 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
self._available = False
self.heater_id = heater.device_id
self._id = heater.device_id
self._attr_unique_id = heater.device_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, heater.device_id)},
@ -147,10 +126,10 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
return
await self.coordinator.mill_data_connection.set_heater_temp(
self.heater_id, float(temperature)
self._id, float(temperature)
)
await self.coordinator.mill_data_connection.fetch_historic_energy_usage(
self.heater_id
self._id
)
await self.coordinator.async_request_refresh()
@ -158,12 +137,12 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
"""Set new target hvac mode."""
if hvac_mode == HVACMode.HEAT:
await self.coordinator.mill_data_connection.heater_control(
self.heater_id, power_status=True
self._id, power_status=True
)
await self.coordinator.async_request_refresh()
elif hvac_mode == HVACMode.OFF:
await self.coordinator.mill_data_connection.heater_control(
self.heater_id, power_status=False
self._id, power_status=False
)
await self.coordinator.async_request_refresh()
@ -175,7 +154,7 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._update_attr(self.coordinator.data[self.heater_id])
self._update_attr(self.coordinator.data[self._id])
self.async_write_ha_state()
@callback

View File

@ -18,6 +18,5 @@ MANUFACTURER = "Mill"
MAX_TEMP = 35
MIN_TEMP = 5
SERVICE_SET_ROOM_TEMP = "set_room_temperature"
SERVICE_MAX_HEATING_POWER = "max_heating_power"
TEMPERATURE = "current_temp"
TVOC = "tvoc"

View File

@ -2,9 +2,6 @@
"services": {
"set_room_temperature": {
"service": "mdi:thermometer"
},
"max_heating_power": {
"service": "mdi:power"
}
}
}

View File

@ -23,20 +23,3 @@ set_room_temperature:
min: 0
max: 100
unit_of_measurement: "°"
max_heating_power:
fields:
entity_id:
required: true
example: "climate.house"
selector:
entity:
integration: mill
domain: climate
max_heating_power:
required: true
selector:
number:
min: 0
max: 2000
unit_of_measurement: "W"

View File

@ -53,20 +53,6 @@
}
},
"services": {
"max_heating_power": {
"description": "Sets max power heater can use.",
"fields": {
"entity_id": {
"description": "Entity id of heater to change.",
"name": "Entity id"
},
"max_heating_power": {
"description": "Max heating power.",
"name": "Max heating power"
}
},
"name": "Set max heating power"
},
"set_room_temperature": {
"name": "Set room temperature",
"description": "Sets Mill room temperatures.",