Add OSO Energy Custom Away Mode Service (#149612)

This commit is contained in:
osohotwateriot 2025-07-29 14:50:31 +03:00 committed by GitHub
parent 87400c6a17
commit c7271d1af9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 69 additions and 0 deletions

View File

@ -22,6 +22,9 @@
"set_v40_min": {
"service": "mdi:car-coolant-level"
},
"turn_away_mode_on": {
"service": "mdi:beach"
},
"turn_off": {
"service": "mdi:water-boiler-off"
},

View File

@ -237,6 +237,20 @@ set_v40_min:
max: 550
step: 1
unit_of_measurement: L
turn_away_mode_on:
target:
entity:
domain: water_heater
fields:
duration_days:
required: true
example: 7
selector:
number:
min: 1
max: 365
step: 1
unit_of_measurement: days
turn_off:
target:
entity:

View File

@ -209,6 +209,16 @@
}
}
},
"turn_away_mode_on": {
"name": "Set away mode",
"description": "Turns away mode on for the heater",
"fields": {
"duration_days": {
"name": "Duration in days",
"description": "Number of days to keep away mode active (1-365)"
}
}
},
"turn_off": {
"name": "Turn off heating",
"description": "Turns off heating for one hour or until min temperature is reached",

View File

@ -26,6 +26,7 @@ from homeassistant.util.json import JsonValueType
from .const import DOMAIN
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] = {
@ -44,6 +45,7 @@ CURRENT_OPERATION_MAP: dict[str, Any] = {
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"
SERVICE_TURN_OFF = "turn_off"
SERVICE_TURN_ON = "turn_on"
@ -69,6 +71,16 @@ async def async_setup_entry(
supports_response=SupportsResponse.ONLY,
)
platform.async_register_entity_service(
SERVICE_TURN_AWAY_MODE_ON,
{
vol.Required(ATTR_DURATION_DAYS): vol.All(
vol.Coerce(int), vol.Range(min=1, max=365)
),
},
OSOEnergyWaterHeater.async_oso_turn_away_mode_on.__name__,
)
service_set_profile_schema = cv.make_entity_service_schema(
{
vol.Optional(f"hour_{hour:02d}"): vol.All(
@ -280,6 +292,12 @@ class OSOEnergyWaterHeater(
"""Handle the service call."""
await self.osoenergy.hotwater.set_v40_min(self.entity_data, v40_min)
async def async_oso_turn_away_mode_on(self, duration_days: int) -> None:
"""Enable away mode with duration."""
await self.osoenergy.hotwater.enable_holiday_mode(
self.entity_data, duration_days
)
async def async_oso_turn_off(self, until_temp_limit) -> None:
"""Handle the service call."""
await self.osoenergy.hotwater.turn_off(self.entity_data, until_temp_limit)

View File

@ -7,11 +7,13 @@ from syrupy.assertion import SnapshotAssertion
from homeassistant.components.osoenergy.const import DOMAIN
from homeassistant.components.osoenergy.water_heater import (
ATTR_DURATION_DAYS,
ATTR_UNTIL_TEMP_LIMIT,
ATTR_V40MIN,
SERVICE_GET_PROFILE,
SERVICE_SET_PROFILE,
SERVICE_SET_V40MIN,
SERVICE_TURN_AWAY_MODE_ON,
)
from homeassistant.components.water_heater import (
ATTR_AWAY_MODE,
@ -310,3 +312,25 @@ async def test_turn_away_mode_off(
)
mock_osoenergy_client().hotwater.disable_holiday_mode.assert_called_once_with(ANY)
async def test_oso_set_away_mode_on(
hass: HomeAssistant,
mock_osoenergy_client: MagicMock,
mock_config_entry: ConfigEntry,
) -> None:
"""Test enabling away mode."""
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_AWAY_MODE_ON,
{
ATTR_ENTITY_ID: "water_heater.test_device",
ATTR_DURATION_DAYS: 10,
},
blocking=True,
)
mock_osoenergy_client().hotwater.enable_holiday_mode.assert_called_once_with(
ANY, 10
)