mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 12:21:04 -04:00
Pass the Genius Hub switch override duration in seconds (#184554)
This commit is contained in:
@@ -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()))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user