Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
Daniel Hjelseth Høyer 2024-11-13 18:37:24 +01:00
parent 182f8b33f7
commit 29c68f3615
5 changed files with 23 additions and 26 deletions

View File

@ -24,7 +24,10 @@ 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
from homeassistant.helpers.entity_platform import (
AddEntitiesCallback,
async_get_current_platform,
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import (
@ -53,12 +56,6 @@ SET_ROOM_TEMP_SCHEMA = vol.Schema(
vol.Optional(ATTR_SLEEP_TEMP): cv.positive_int,
}
)
LIMIT_HEATING_POWER_SCHEMA = vol.Schema(
{
vol.Required(ATTR_ENTITY_ID): cv.entity_id,
vol.Required(ATTR_MAX_HEATING_POWER): vol.Range(min=0, max=2000),
}
)
async def async_setup_entry(
@ -93,23 +90,19 @@ async def async_setup_entry(
DOMAIN, SERVICE_SET_ROOM_TEMP, set_room_temp, schema=SET_ROOM_TEMP_SCHEMA
)
async def max_heating_power(service: ServiceCall) -> None:
async def max_heating_power(entity: MillHeater, service: ServiceCall) -> None:
"""Limit heating power."""
entity_id = service.data.get(ATTR_ENTITY_ID)
heating_power = service.data.get(ATTR_MAX_HEATING_POWER)
for entity in entities:
if entity.entity_id == entity_id:
await mill_data_coordinator.mill_data_connection.max_heating_power(
entity.heater_id, heating_power
entity.heater_id, service.data[ATTR_MAX_HEATING_POWER]
)
return
raise ValueError(f"Entity id {entity_id} not found")
hass.services.async_register(
DOMAIN,
async_get_current_platform().async_register_entity_service(
SERVICE_MAX_HEATING_POWER,
max_heating_power,
schema=LIMIT_HEATING_POWER_SCHEMA,
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,
)

View File

@ -72,6 +72,7 @@ class MillDataUpdateCoordinator(DataUpdateCoordinator):
hourly_data = (
await self.mill_data_connection.fetch_historic_energy_usage(dev_id)
)
hourly_data = dict(sorted(hourly_data.items(), key=lambda x: x[0]))
_sum = 0.0
last_stats_time = None
else:
@ -84,15 +85,18 @@ class MillDataUpdateCoordinator(DataUpdateCoordinator):
last_stats[statistic_id][0]["start"]
)
).days
+ 1,
+ 2,
)
)
if not hourly_data:
return
hourly_data = dict(sorted(hourly_data.items(), key=lambda x: x[0]))
start_time = next(iter(hourly_data))
stats = await get_instance(self.hass).async_add_executor_job(
statistics_during_period,
self.hass,
next(iter(hourly_data)),
start_time,
None,
{statistic_id},
"hour",

View File

@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/mill",
"iot_class": "local_polling",
"loggers": ["mill", "mill_local"],
"requirements": ["millheater==0.12.0", "mill-local==0.3.0"]
"requirements": ["millheater==0.12.1", "mill-local==0.3.0"]
}

View File

@ -1373,7 +1373,7 @@ microBeesPy==0.3.2
mill-local==0.3.0
# homeassistant.components.mill
millheater==0.12.0
millheater==0.12.1
# homeassistant.components.minio
minio==7.1.12

View File

@ -1142,7 +1142,7 @@ microBeesPy==0.3.2
mill-local==0.3.0
# homeassistant.components.mill
millheater==0.12.0
millheater==0.12.1
# homeassistant.components.minio
minio==7.1.12