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.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 AddEntitiesCallback from homeassistant.helpers.entity_platform import (
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 (
@ -53,12 +56,6 @@ SET_ROOM_TEMP_SCHEMA = vol.Schema(
vol.Optional(ATTR_SLEEP_TEMP): cv.positive_int, 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( 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 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.""" """Limit heating power."""
entity_id = service.data.get(ATTR_ENTITY_ID) await mill_data_coordinator.mill_data_connection.max_heating_power(
heating_power = service.data.get(ATTR_MAX_HEATING_POWER) entity.heater_id, service.data[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
)
return
raise ValueError(f"Entity id {entity_id} not found")
hass.services.async_register( async_get_current_platform().async_register_entity_service(
DOMAIN,
SERVICE_MAX_HEATING_POWER, SERVICE_MAX_HEATING_POWER,
max_heating_power, schema={
schema=LIMIT_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,
) )

View File

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

View File

@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/mill", "documentation": "https://www.home-assistant.io/integrations/mill",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["mill", "mill_local"], "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 mill-local==0.3.0
# homeassistant.components.mill # homeassistant.components.mill
millheater==0.12.0 millheater==0.12.1
# homeassistant.components.minio # homeassistant.components.minio
minio==7.1.12 minio==7.1.12

View File

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