mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Move osoenergy service registration to services module (#184628)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5d602872dc
commit
9ec6a003e6
@@ -10,7 +10,11 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .services import async_setup_services
|
||||
|
||||
type OSOEnergyConfigEntry = ConfigEntry[OSOEnergy]
|
||||
|
||||
@@ -26,6 +30,15 @@ PLATFORM_LOOKUP = {
|
||||
}
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the OSO Energy integration."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: OSOEnergyConfigEntry) -> bool:
|
||||
"""Set up OSO Energy from a config entry."""
|
||||
subscription_key = entry.data[CONF_API_KEY]
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
"""Services for the OSO Energy integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER_DOMAIN
|
||||
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant, SupportsResponse, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
ATTR_DURATION_DAYS = "duration_days"
|
||||
ATTR_UNTIL_TEMP_LIMIT = "until_temp_limit"
|
||||
ATTR_V40MIN = "v40_min"
|
||||
SERVICE_GET_PROFILE = "get_profile"
|
||||
SERVICE_SET_PROFILE = "set_profile"
|
||||
SERVICE_SET_V40MIN = "set_v40_min"
|
||||
SERVICE_TURN_AWAY_MODE_ON = "turn_away_mode_on"
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the OSO Energy integration."""
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_GET_PROFILE,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema={},
|
||||
func="async_get_profile",
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TURN_AWAY_MODE_ON,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema={
|
||||
probatio.Required(ATTR_DURATION_DAYS): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=1, max=365)
|
||||
),
|
||||
},
|
||||
func="async_oso_turn_away_mode_on",
|
||||
)
|
||||
|
||||
service_set_profile_schema = cv.make_entity_service_schema(
|
||||
{
|
||||
probatio.Optional(f"hour_{hour:02d}"): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=10, max=75)
|
||||
)
|
||||
for hour in range(24)
|
||||
}
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_PROFILE,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema=service_set_profile_schema,
|
||||
func="async_set_profile",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_SET_V40MIN,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema={
|
||||
probatio.Required(ATTR_V40MIN): probatio.All(
|
||||
probatio.Coerce(float), probatio.Range(min=200, max=550)
|
||||
),
|
||||
},
|
||||
func="async_set_v40_min",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema={probatio.Required(ATTR_UNTIL_TEMP_LIMIT): probatio.All(cv.boolean)},
|
||||
func="async_oso_turn_off",
|
||||
)
|
||||
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
entity_domain=WATER_HEATER_DOMAIN,
|
||||
schema={probatio.Required(ATTR_UNTIL_TEMP_LIMIT): probatio.All(cv.boolean)},
|
||||
func="async_oso_turn_on",
|
||||
)
|
||||
@@ -5,7 +5,6 @@ from typing import Any, override
|
||||
|
||||
from apyosoenergyapi import OSOEnergy
|
||||
from apyosoenergyapi.helper.const import OSOEnergyWaterHeaterData
|
||||
import probatio
|
||||
|
||||
from homeassistant.components.water_heater import (
|
||||
STATE_ECO,
|
||||
@@ -15,9 +14,8 @@ from homeassistant.components.water_heater import (
|
||||
WaterHeaterEntity,
|
||||
WaterHeaterEntityFeature,
|
||||
)
|
||||
from homeassistant.const import SERVICE_TURN_OFF, SERVICE_TURN_ON, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, ServiceResponse, SupportsResponse
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, ServiceResponse
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.json import JsonValueType
|
||||
@@ -25,9 +23,6 @@ from homeassistant.util.json import JsonValueType
|
||||
from . import OSOEnergyConfigEntry
|
||||
from .entity import OSOEnergyEntity
|
||||
|
||||
ATTR_DURATION_DAYS = "duration_days"
|
||||
ATTR_UNTIL_TEMP_LIMIT = "until_temp_limit"
|
||||
ATTR_V40MIN = "v40_min"
|
||||
CURRENT_OPERATION_MAP: dict[str, Any] = {
|
||||
"default": {
|
||||
"off": STATE_OFF,
|
||||
@@ -41,10 +36,6 @@ CURRENT_OPERATION_MAP: dict[str, Any] = {
|
||||
"extraenergy": STATE_HIGH_DEMAND,
|
||||
},
|
||||
}
|
||||
SERVICE_GET_PROFILE = "get_profile"
|
||||
SERVICE_SET_PROFILE = "set_profile"
|
||||
SERVICE_SET_V40MIN = "set_v40_min"
|
||||
SERVICE_TURN_AWAY_MODE_ON = "turn_away_mode_on"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@@ -59,62 +50,6 @@ async def async_setup_entry(
|
||||
return
|
||||
async_add_entities((OSOEnergyWaterHeater(osoenergy, dev) for dev in devices), True)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_GET_PROFILE,
|
||||
{},
|
||||
OSOEnergyWaterHeater.async_get_profile.__name__,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TURN_AWAY_MODE_ON,
|
||||
{
|
||||
probatio.Required(ATTR_DURATION_DAYS): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=1, max=365)
|
||||
),
|
||||
},
|
||||
OSOEnergyWaterHeater.async_oso_turn_away_mode_on.__name__,
|
||||
)
|
||||
|
||||
service_set_profile_schema = cv.make_entity_service_schema(
|
||||
{
|
||||
probatio.Optional(f"hour_{hour:02d}"): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(min=10, max=75)
|
||||
)
|
||||
for hour in range(24)
|
||||
}
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_PROFILE,
|
||||
service_set_profile_schema,
|
||||
OSOEnergyWaterHeater.async_set_profile.__name__,
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_V40MIN,
|
||||
{
|
||||
probatio.Required(ATTR_V40MIN): probatio.All(
|
||||
probatio.Coerce(float), probatio.Range(min=200, max=550)
|
||||
),
|
||||
},
|
||||
OSOEnergyWaterHeater.async_set_v40_min.__name__,
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TURN_OFF,
|
||||
{probatio.Required(ATTR_UNTIL_TEMP_LIMIT): probatio.All(cv.boolean)},
|
||||
OSOEnergyWaterHeater.async_oso_turn_off.__name__,
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TURN_ON,
|
||||
{probatio.Required(ATTR_UNTIL_TEMP_LIMIT): probatio.All(cv.boolean)},
|
||||
OSOEnergyWaterHeater.async_oso_turn_on.__name__,
|
||||
)
|
||||
|
||||
|
||||
def _get_utc_hour(local_hour: int) -> dt.datetime:
|
||||
"""Convert the requested local hour to a utc hour for the day.
|
||||
|
||||
@@ -6,7 +6,7 @@ import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.osoenergy.const import DOMAIN
|
||||
from homeassistant.components.osoenergy.water_heater import (
|
||||
from homeassistant.components.osoenergy.services import (
|
||||
ATTR_DURATION_DAYS,
|
||||
ATTR_UNTIL_TEMP_LIMIT,
|
||||
ATTR_V40MIN,
|
||||
|
||||
Reference in New Issue
Block a user