diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index 54791eac92f..e4ffbcba23e 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -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 - ) - return - raise ValueError(f"Entity id {entity_id} not found") + await mill_data_coordinator.mill_data_connection.max_heating_power( + entity.heater_id, service.data[ATTR_MAX_HEATING_POWER] + ) - 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, ) diff --git a/homeassistant/components/mill/coordinator.py b/homeassistant/components/mill/coordinator.py index a83d28fc031..f5e2b1ba6dd 100644 --- a/homeassistant/components/mill/coordinator.py +++ b/homeassistant/components/mill/coordinator.py @@ -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", diff --git a/homeassistant/components/mill/manifest.json b/homeassistant/components/mill/manifest.json index 05ec456162d..8dd1424e2ba 100644 --- a/homeassistant/components/mill/manifest.json +++ b/homeassistant/components/mill/manifest.json @@ -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"] } diff --git a/requirements_all.txt b/requirements_all.txt index 671cd6b1f78..806b1604d10 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 10ed0c5618a..d67da8efe6b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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