mirror of
https://github.com/home-assistant/core.git
synced 2026-12-06 05:38:06 -04:00
Move hive service registration to services module (#184607)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1219a56e6b
commit
4a2a85b874
@@ -12,17 +12,32 @@ from apyhiveapi.helper.hive_exceptions import HiveReauthRequired
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
||||
from homeassistant.helpers import (
|
||||
aiohttp_client,
|
||||
config_validation as cv,
|
||||
device_registry as dr,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN, PLATFORMS
|
||||
from .entity import HiveEntity
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type HiveConfigEntry = ConfigEntry[Hive]
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Hive integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: HiveConfigEntry) -> bool:
|
||||
"""Set up Hive from a config entry."""
|
||||
web_session = aiohttp_client.async_get_clientsession(hass)
|
||||
|
||||
@@ -5,7 +5,6 @@ import logging
|
||||
from typing import Any, override
|
||||
|
||||
from apyhiveapi import Hive
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
PRESET_BOOST,
|
||||
@@ -17,11 +16,9 @@ from homeassistant.components.climate import (
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import HiveConfigEntry, refresh_system
|
||||
from .const import ATTR_TIME_PERIOD, SERVICE_BOOST_HEATING_OFF, SERVICE_BOOST_HEATING_ON
|
||||
from .entity import HiveEntity
|
||||
|
||||
HIVE_TO_HASS_STATE = {
|
||||
@@ -65,27 +62,6 @@ async def async_setup_entry(
|
||||
(HiveClimateEntity(hass, entry, hive, dev) for dev in devices), True
|
||||
)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_BOOST_HEATING_ON,
|
||||
{
|
||||
probatio.Required(ATTR_TIME_PERIOD): probatio.All(
|
||||
cv.time_period,
|
||||
cv.positive_timedelta,
|
||||
lambda td: td.total_seconds() // 60,
|
||||
),
|
||||
probatio.Optional(ATTR_TEMPERATURE, default="25.0"): probatio.Coerce(float),
|
||||
},
|
||||
"async_heating_boost_on",
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_BOOST_HEATING_OFF,
|
||||
None,
|
||||
"async_heating_boost_off",
|
||||
)
|
||||
|
||||
|
||||
class HiveClimateEntity(HiveEntity, ClimateEntity):
|
||||
"""Hive Climate Device."""
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Services for the Hive integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
|
||||
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER_DOMAIN
|
||||
from homeassistant.const import ATTR_TEMPERATURE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import (
|
||||
ATTR_ONOFF,
|
||||
ATTR_TIME_PERIOD,
|
||||
DOMAIN,
|
||||
SERVICE_BOOST_HEATING_OFF,
|
||||
SERVICE_BOOST_HEATING_ON,
|
||||
SERVICE_BOOST_HOT_WATER,
|
||||
WATER_HEATER_MODES,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Hive integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_BOOST_HEATING_ON,
|
||||
entity_domain=CLIMATE_DOMAIN,
|
||||
schema={
|
||||
probatio.Required(ATTR_TIME_PERIOD): probatio.All(
|
||||
cv.time_period,
|
||||
cv.positive_timedelta,
|
||||
lambda td: td.total_seconds() // 60,
|
||||
),
|
||||
probatio.Optional(ATTR_TEMPERATURE, default="25.0"): probatio.Coerce(float),
|
||||
},
|
||||
func="async_heating_boost_on",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_BOOST_HEATING_OFF,
|
||||
entity_domain=CLIMATE_DOMAIN,
|
||||
schema=None,
|
||||
func="async_heating_boost_off",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_BOOST_HOT_WATER,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema={
|
||||
probatio.Optional(ATTR_TIME_PERIOD, default="00:30:00"): probatio.All(
|
||||
cv.time_period,
|
||||
cv.positive_timedelta,
|
||||
lambda td: td.total_seconds() // 60,
|
||||
),
|
||||
probatio.Required(ATTR_ONOFF): probatio.In(WATER_HEATER_MODES),
|
||||
},
|
||||
func="async_hot_water_boost",
|
||||
)
|
||||
@@ -3,8 +3,6 @@
|
||||
from datetime import timedelta
|
||||
from typing import Any, override
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.water_heater import (
|
||||
STATE_ECO,
|
||||
WaterHeaterEntity,
|
||||
@@ -12,16 +10,9 @@ from homeassistant.components.water_heater import (
|
||||
)
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import HiveConfigEntry, refresh_system
|
||||
from .const import (
|
||||
ATTR_ONOFF,
|
||||
ATTR_TIME_PERIOD,
|
||||
SERVICE_BOOST_HOT_WATER,
|
||||
WATER_HEATER_MODES,
|
||||
)
|
||||
from .entity import HiveEntity
|
||||
|
||||
HOTWATER_NAME = "Hot Water"
|
||||
@@ -56,21 +47,6 @@ async def async_setup_entry(
|
||||
(HiveWaterHeater(hass, entry, hive, dev) for dev in devices), True
|
||||
)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_BOOST_HOT_WATER,
|
||||
{
|
||||
probatio.Optional(ATTR_TIME_PERIOD, default="00:30:00"): probatio.All(
|
||||
cv.time_period,
|
||||
cv.positive_timedelta,
|
||||
lambda td: td.total_seconds() // 60,
|
||||
),
|
||||
probatio.Required(ATTR_ONOFF): probatio.In(WATER_HEATER_MODES),
|
||||
},
|
||||
"async_hot_water_boost",
|
||||
)
|
||||
|
||||
|
||||
class HiveWaterHeater(HiveEntity, WaterHeaterEntity):
|
||||
"""Hive Water Heater Device."""
|
||||
|
||||
Reference in New Issue
Block a user