Pass the Genius Hub switch override duration in seconds (#184554)

This commit is contained in:
Franck Nijhof
2026-10-06 22:33:42 -04:00
committed by GitHub
parent e1829b1804
commit bcd0f93bd4
2 changed files with 48 additions and 3 deletions
+3 -1
View File
@@ -1,5 +1,6 @@
"""Support for Genius Hub switch/outlet devices."""
from datetime import timedelta
from typing import Any, override
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
@@ -61,4 +62,5 @@ class GeniusSwitch(GeniusZone, SwitchEntity):
@override
async def async_turn_on(self, **kwargs: Any) -> None:
"""Set the zone to override/on ({'setpoint': true}) for x seconds."""
await self._zone.set_override(1, kwargs.get(ATTR_DURATION, 3600))
duration: timedelta = kwargs.get(ATTR_DURATION, timedelta(hours=1))
await self._zone.set_override(1, int(duration.total_seconds()))
+45 -2
View File
@@ -1,11 +1,13 @@
"""Tests for the Geniushub switch platform."""
from unittest.mock import patch
from unittest.mock import ANY, patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.const import Platform
from homeassistant.components.geniushub.const import DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@@ -28,3 +30,44 @@ async def test_cloud_all_sensors(
await snapshot_platform(
hass, entity_registry, snapshot, mock_cloud_config_entry.entry_id
)
@pytest.mark.usefixtures("mock_geniushub_cloud")
@pytest.mark.parametrize(
("domain", "service", "service_data", "expected_duration"),
[
pytest.param(
SWITCH_DOMAIN, SERVICE_TURN_ON, {}, 3600, id="turn_on_default_duration"
),
pytest.param(
DOMAIN,
"set_switch_override",
{"duration": 36000},
36000,
id="set_switch_override_duration",
),
],
)
async def test_turn_on_override_duration(
hass: HomeAssistant,
mock_cloud_config_entry: MockConfigEntry,
domain: str,
service: str,
service_data: dict[str, int],
expected_duration: int,
) -> None:
"""Test turning on a switch zone overrides it for a duration in seconds."""
with patch("homeassistant.components.geniushub.PLATFORMS", [Platform.SWITCH]):
await setup_integration(hass, mock_cloud_config_entry)
with patch(
"geniushubclient.zone.GeniusZone.set_override", autospec=True
) as mock_set_override:
await hass.services.async_call(
domain,
service,
{ATTR_ENTITY_ID: "switch.bedroom_socket", **service_data},
blocking=True,
)
mock_set_override.assert_awaited_once_with(ANY, 1, expected_duration)