Add an action enum to monoprice (#190635)

This commit is contained in:
epenet
2026-11-09 09:36:31 +00:00
committed by GitHub
parent 552afe9bed
commit e88d6c05f9
3 changed files with 31 additions and 16 deletions
@@ -12,6 +12,3 @@ CONF_SOURCE_5 = "source_5"
CONF_SOURCE_6 = "source_6"
CONF_NOT_FIRST_RUN = "not_first_run"
SERVICE_SNAPSHOT = "snapshot"
SERVICE_RESTORE = "restore"
+12 -3
View File
@@ -1,10 +1,19 @@
"""Services for the monoprice integration."""
from enum import StrEnum
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import service
from .const import DOMAIN, SERVICE_RESTORE, SERVICE_SNAPSHOT
from .const import DOMAIN
class MonopriceService(StrEnum):
"""Store keys for Monoprice services."""
SNAPSHOT = "snapshot"
RESTORE = "restore"
@callback
@@ -13,7 +22,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_SNAPSHOT,
MonopriceService.SNAPSHOT,
entity_domain=MEDIA_PLAYER_DOMAIN,
schema=None,
func="snapshot",
@@ -21,7 +30,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
service.async_register_platform_entity_service(
hass,
DOMAIN,
SERVICE_RESTORE,
MonopriceService.RESTORE,
entity_domain=MEDIA_PLAYER_DOMAIN,
schema=None,
func="restore",
+19 -10
View File
@@ -19,9 +19,8 @@ from homeassistant.components.monoprice.const import (
CONF_NOT_FIRST_RUN,
CONF_SOURCES,
DOMAIN,
SERVICE_RESTORE,
SERVICE_SNAPSHOT,
)
from homeassistant.components.monoprice.services import MonopriceService
from homeassistant.const import (
CONF_PORT,
SERVICE_TURN_OFF,
@@ -172,7 +171,9 @@ async def test_service_calls_with_entity_id(hass: HomeAssistant) -> None:
)
# Saving existing values
await _call_monoprice_service(hass, SERVICE_SNAPSHOT, {"entity_id": ZONE_1_ID})
await _call_monoprice_service(
hass, MonopriceService.SNAPSHOT, {"entity_id": ZONE_1_ID}
)
# Changing media player to new state
await _call_media_player_service(
@@ -184,7 +185,9 @@ async def test_service_calls_with_entity_id(hass: HomeAssistant) -> None:
# Restoring other media player to its previous state
# The zone should not be restored
await _call_monoprice_service(hass, SERVICE_RESTORE, {"entity_id": ZONE_2_ID})
await _call_monoprice_service(
hass, MonopriceService.RESTORE, {"entity_id": ZONE_2_ID}
)
await hass.async_block_till_done(wait_background_tasks=True)
# Checking that values were not (!) restored
@@ -194,7 +197,9 @@ async def test_service_calls_with_entity_id(hass: HomeAssistant) -> None:
assert state.attributes[ATTR_INPUT_SOURCE] == "three"
# Restoring media player to its previous state
await _call_monoprice_service(hass, SERVICE_RESTORE, {"entity_id": ZONE_1_ID})
await _call_monoprice_service(
hass, MonopriceService.RESTORE, {"entity_id": ZONE_1_ID}
)
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ZONE_1_ID)
@@ -216,7 +221,7 @@ async def test_service_calls_with_all_entities(hass: HomeAssistant) -> None:
)
# Saving existing values
await _call_monoprice_service(hass, SERVICE_SNAPSHOT, {"entity_id": "all"})
await _call_monoprice_service(hass, MonopriceService.SNAPSHOT, {"entity_id": "all"})
# Changing media player to new state
await _call_media_player_service(
@@ -227,7 +232,7 @@ async def test_service_calls_with_all_entities(hass: HomeAssistant) -> None:
)
# Restoring media player to its previous state
await _call_monoprice_service(hass, SERVICE_RESTORE, {"entity_id": "all"})
await _call_monoprice_service(hass, MonopriceService.RESTORE, {"entity_id": "all"})
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ZONE_1_ID)
@@ -249,7 +254,7 @@ async def test_service_calls_without_relevant_entities(hass: HomeAssistant) -> N
)
# Saving existing values
await _call_monoprice_service(hass, SERVICE_SNAPSHOT, {"entity_id": "all"})
await _call_monoprice_service(hass, MonopriceService.SNAPSHOT, {"entity_id": "all"})
# Changing media player to new state
await _call_media_player_service(
@@ -260,7 +265,9 @@ async def test_service_calls_without_relevant_entities(hass: HomeAssistant) -> N
)
# Restoring media player to its previous state
await _call_monoprice_service(hass, SERVICE_RESTORE, {"entity_id": "light.demo"})
await _call_monoprice_service(
hass, MonopriceService.RESTORE, {"entity_id": "light.demo"}
)
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ZONE_1_ID)
@@ -274,7 +281,9 @@ async def test_restore_without_snapshort(hass: HomeAssistant) -> None:
await _setup_monoprice(hass, MockMonoprice())
with patch.object(MockMonoprice, "restore_zone") as method_call:
await _call_monoprice_service(hass, SERVICE_RESTORE, {"entity_id": ZONE_1_ID})
await _call_monoprice_service(
hass, MonopriceService.RESTORE, {"entity_id": ZONE_1_ID}
)
await hass.async_block_till_done(wait_background_tasks=True)
assert not method_call.called