mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
mill
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
parent
16b6da9c91
commit
5b7f5fef88
@ -14,7 +14,6 @@ from homeassistant.components.climate import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
CONF_IP_ADDRESS,
|
CONF_IP_ADDRESS,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
@ -24,16 +23,12 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import (
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
AddEntitiesCallback,
|
|
||||||
async_get_current_platform,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_AWAY_TEMP,
|
ATTR_AWAY_TEMP,
|
||||||
ATTR_COMFORT_TEMP,
|
ATTR_COMFORT_TEMP,
|
||||||
ATTR_MAX_HEATING_POWER,
|
|
||||||
ATTR_ROOM_NAME,
|
ATTR_ROOM_NAME,
|
||||||
ATTR_SLEEP_TEMP,
|
ATTR_SLEEP_TEMP,
|
||||||
CLOUD,
|
CLOUD,
|
||||||
@ -43,7 +38,6 @@ from .const import (
|
|||||||
MANUFACTURER,
|
MANUFACTURER,
|
||||||
MAX_TEMP,
|
MAX_TEMP,
|
||||||
MIN_TEMP,
|
MIN_TEMP,
|
||||||
SERVICE_MAX_HEATING_POWER,
|
|
||||||
SERVICE_SET_ROOM_TEMP,
|
SERVICE_SET_ROOM_TEMP,
|
||||||
)
|
)
|
||||||
from .coordinator import MillDataUpdateCoordinator
|
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
|
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):
|
class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
|
||||||
"""Representation of a Mill Thermostat device."""
|
"""Representation of a Mill Thermostat device."""
|
||||||
@ -131,7 +110,7 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
|
|||||||
|
|
||||||
self._available = False
|
self._available = False
|
||||||
|
|
||||||
self.heater_id = heater.device_id
|
self._id = heater.device_id
|
||||||
self._attr_unique_id = heater.device_id
|
self._attr_unique_id = heater.device_id
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, heater.device_id)},
|
identifiers={(DOMAIN, heater.device_id)},
|
||||||
@ -147,10 +126,10 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
|
|||||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||||
return
|
return
|
||||||
await self.coordinator.mill_data_connection.set_heater_temp(
|
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(
|
await self.coordinator.mill_data_connection.fetch_historic_energy_usage(
|
||||||
self.heater_id
|
self._id
|
||||||
)
|
)
|
||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
|
|
||||||
@ -158,12 +137,12 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
|
|||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
if hvac_mode == HVACMode.HEAT:
|
if hvac_mode == HVACMode.HEAT:
|
||||||
await self.coordinator.mill_data_connection.heater_control(
|
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()
|
await self.coordinator.async_request_refresh()
|
||||||
elif hvac_mode == HVACMode.OFF:
|
elif hvac_mode == HVACMode.OFF:
|
||||||
await self.coordinator.mill_data_connection.heater_control(
|
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()
|
await self.coordinator.async_request_refresh()
|
||||||
|
|
||||||
@ -175,7 +154,7 @@ class MillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntity):
|
|||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Handle updated data from the coordinator."""
|
"""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()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -18,6 +18,5 @@ MANUFACTURER = "Mill"
|
|||||||
MAX_TEMP = 35
|
MAX_TEMP = 35
|
||||||
MIN_TEMP = 5
|
MIN_TEMP = 5
|
||||||
SERVICE_SET_ROOM_TEMP = "set_room_temperature"
|
SERVICE_SET_ROOM_TEMP = "set_room_temperature"
|
||||||
SERVICE_MAX_HEATING_POWER = "max_heating_power"
|
|
||||||
TEMPERATURE = "current_temp"
|
TEMPERATURE = "current_temp"
|
||||||
TVOC = "tvoc"
|
TVOC = "tvoc"
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
"services": {
|
"services": {
|
||||||
"set_room_temperature": {
|
"set_room_temperature": {
|
||||||
"service": "mdi:thermometer"
|
"service": "mdi:thermometer"
|
||||||
},
|
|
||||||
"max_heating_power": {
|
|
||||||
"service": "mdi:power"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,20 +23,3 @@ set_room_temperature:
|
|||||||
min: 0
|
min: 0
|
||||||
max: 100
|
max: 100
|
||||||
unit_of_measurement: "°"
|
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"
|
|
||||||
|
@ -53,20 +53,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"services": {
|
"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": {
|
"set_room_temperature": {
|
||||||
"name": "Set room temperature",
|
"name": "Set room temperature",
|
||||||
"description": "Sets Mill room temperatures.",
|
"description": "Sets Mill room temperatures.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user