mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Remove deprecated 'heos.sign_in' and 'heos.sign_out' actions in HEOS integration (#187102)
This commit is contained in:
@@ -12,5 +12,3 @@ SERVICE_GROUP_VOLUME_DOWN = "group_volume_down"
|
||||
SERVICE_GROUP_VOLUME_UP = "group_volume_up"
|
||||
SERVICE_MOVE_QUEUE_ITEM = "move_queue_item"
|
||||
SERVICE_REMOVE_FROM_QUEUE = "remove_from_queue"
|
||||
SERVICE_SIGN_IN = "sign_in"
|
||||
SERVICE_SIGN_OUT = "sign_out"
|
||||
|
||||
@@ -17,12 +17,6 @@
|
||||
},
|
||||
"remove_from_queue": {
|
||||
"service": "mdi:playlist-remove"
|
||||
},
|
||||
"sign_in": {
|
||||
"service": "mdi:login"
|
||||
},
|
||||
"sign_out": {
|
||||
"service": "mdi:logout"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,19 @@ import logging
|
||||
from typing import Final
|
||||
|
||||
import probatio
|
||||
from pyheos import CommandAuthenticationError, Heos, HeosError
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
ATTR_MEDIA_VOLUME_LEVEL,
|
||||
DOMAIN as MEDIA_PLAYER_DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, SupportsResponse, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv, issue_registry as ir
|
||||
from homeassistant.core import HomeAssistant, SupportsResponse, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.service import async_register_platform_entity_service
|
||||
from homeassistant.helpers.typing import VolDictType, VolSchemaType
|
||||
|
||||
from .const import (
|
||||
ATTR_DESTINATION_POSITION,
|
||||
ATTR_PASSWORD,
|
||||
ATTR_QUEUE_IDS,
|
||||
ATTR_USERNAME,
|
||||
DOMAIN,
|
||||
SERVICE_GET_QUEUE,
|
||||
SERVICE_GROUP_VOLUME_DOWN,
|
||||
@@ -30,38 +25,14 @@ from .const import (
|
||||
SERVICE_GROUP_VOLUME_UP,
|
||||
SERVICE_MOVE_QUEUE_ITEM,
|
||||
SERVICE_REMOVE_FROM_QUEUE,
|
||||
SERVICE_SIGN_IN,
|
||||
SERVICE_SIGN_OUT,
|
||||
)
|
||||
from .coordinator import HeosConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
HEOS_SIGN_IN_SCHEMA = probatio.Schema(
|
||||
{
|
||||
probatio.Required(ATTR_USERNAME): cv.string,
|
||||
probatio.Required(ATTR_PASSWORD): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
HEOS_SIGN_OUT_SCHEMA = probatio.Schema({})
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register HEOS services."""
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_IN,
|
||||
_sign_in_handler,
|
||||
schema=HEOS_SIGN_IN_SCHEMA,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_OUT,
|
||||
_sign_out_handler,
|
||||
schema=HEOS_SIGN_OUT_SCHEMA,
|
||||
)
|
||||
for description in MEDIA_PLAYER_ENTITY_SERVICES:
|
||||
async_register_platform_entity_service(
|
||||
hass,
|
||||
@@ -125,62 +96,3 @@ MEDIA_PLAYER_ENTITY_SERVICES: Final = (
|
||||
EntityServiceDescription(SERVICE_GROUP_VOLUME_DOWN, "async_group_volume_down"),
|
||||
EntityServiceDescription(SERVICE_GROUP_VOLUME_UP, "async_group_volume_up"),
|
||||
)
|
||||
|
||||
|
||||
def _get_controller(hass: HomeAssistant) -> Heos:
|
||||
"""Get the HEOS controller instance."""
|
||||
_LOGGER.warning(
|
||||
"Actions 'heos.sign_in' and 'heos.sign_out' are deprecated"
|
||||
" and will be removed in the 2025.8.0 release"
|
||||
)
|
||||
ir.async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"sign_in_out_deprecated",
|
||||
breaks_in_ha_version="2025.8.0",
|
||||
is_fixable=False,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="sign_in_out_deprecated",
|
||||
)
|
||||
|
||||
entry: HeosConfigEntry | None = (
|
||||
hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, DOMAIN)
|
||||
)
|
||||
|
||||
if not entry or entry.state is not ConfigEntryState.LOADED:
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN, translation_key="integration_not_loaded"
|
||||
)
|
||||
return entry.runtime_data.heos
|
||||
|
||||
|
||||
async def _sign_in_handler(service: ServiceCall) -> None:
|
||||
"""Sign in to the HEOS account."""
|
||||
controller = _get_controller(service.hass)
|
||||
username = service.data[ATTR_USERNAME]
|
||||
password = service.data[ATTR_PASSWORD]
|
||||
try:
|
||||
await controller.sign_in(username, password)
|
||||
except CommandAuthenticationError as err:
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN, translation_key="sign_in_auth_error"
|
||||
) from err
|
||||
except HeosError as err:
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="sign_in_error",
|
||||
translation_placeholders={"error": str(err)},
|
||||
) from err
|
||||
|
||||
|
||||
async def _sign_out_handler(service: ServiceCall) -> None:
|
||||
"""Sign out of the HEOS account."""
|
||||
controller = _get_controller(service.hass)
|
||||
try:
|
||||
await controller.sign_out()
|
||||
except HeosError as err:
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="sign_out_error",
|
||||
translation_placeholders={"error": str(err)},
|
||||
) from err
|
||||
|
||||
@@ -62,18 +62,3 @@ group_volume_up:
|
||||
entity:
|
||||
integration: heos
|
||||
domain: media_player
|
||||
|
||||
sign_in:
|
||||
fields:
|
||||
username:
|
||||
required: true
|
||||
example: "example@example.com"
|
||||
selector:
|
||||
text:
|
||||
password:
|
||||
required: true
|
||||
example: "password"
|
||||
selector:
|
||||
text:
|
||||
|
||||
sign_out:
|
||||
|
||||
@@ -60,21 +60,9 @@
|
||||
"entity_not_grouped": {
|
||||
"message": "Entity {entity_id} is not joined to a group"
|
||||
},
|
||||
"integration_not_loaded": {
|
||||
"message": "The HEOS integration is not loaded"
|
||||
},
|
||||
"not_heos_media_player": {
|
||||
"message": "Entity {entity_id} is not a HEOS media player entity"
|
||||
},
|
||||
"sign_in_auth_error": {
|
||||
"message": "Failed to sign in: Invalid username and/or password"
|
||||
},
|
||||
"sign_in_error": {
|
||||
"message": "Unable to sign in: {error}"
|
||||
},
|
||||
"sign_out_error": {
|
||||
"message": "Unable to sign out: {error}"
|
||||
},
|
||||
"unable_to_connect": {
|
||||
"message": "Unable to connect to {host}"
|
||||
},
|
||||
@@ -88,12 +76,6 @@
|
||||
"message": "Unsupported media_content_id: {media_content_id}"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"sign_in_out_deprecated": {
|
||||
"description": "Actions 'heos.sign_in' and 'heos.sign_out' are deprecated and will be removed in the 2025.8.0 release. Enter your HEOS Account credentials in the configuration options and the integration will manage authentication automatically.",
|
||||
"title": "HEOS Actions Deprecated"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"error": {
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
@@ -162,24 +144,6 @@
|
||||
}
|
||||
},
|
||||
"name": "Remove from queue"
|
||||
},
|
||||
"sign_in": {
|
||||
"description": "Signs in to a HEOS account.",
|
||||
"fields": {
|
||||
"password": {
|
||||
"description": "The password of the HEOS account.",
|
||||
"name": "[%key:common::config_flow::data::password%]"
|
||||
},
|
||||
"username": {
|
||||
"description": "The username or email of the HEOS account.",
|
||||
"name": "[%key:common::config_flow::data::username%]"
|
||||
}
|
||||
},
|
||||
"name": "Sign in"
|
||||
},
|
||||
"sign_out": {
|
||||
"description": "Signs out of the HEOS account.",
|
||||
"name": "Sign out"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
"""Tests for the services module."""
|
||||
|
||||
from pyheos import CommandAuthenticationError, HeosError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.heos.const import (
|
||||
ATTR_PASSWORD,
|
||||
ATTR_USERNAME,
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_IN,
|
||||
SERVICE_SIGN_OUT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
|
||||
from . import MockHeos
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_sign_in(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, controller: MockHeos
|
||||
) -> None:
|
||||
"""Test the sign-in service."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_IN,
|
||||
{ATTR_USERNAME: "test@test.com", ATTR_PASSWORD: "password"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
controller.sign_in.assert_called_once_with("test@test.com", "password")
|
||||
|
||||
|
||||
async def test_sign_in_failed(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, controller: MockHeos
|
||||
) -> None:
|
||||
"""Test sign-in service logs error when not connected."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
controller.sign_in.side_effect = CommandAuthenticationError(
|
||||
"", "Invalid credentials", 6
|
||||
)
|
||||
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_IN,
|
||||
{ATTR_USERNAME: "test@test.com", ATTR_PASSWORD: "password"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
controller.sign_in.assert_called_once_with("test@test.com", "password")
|
||||
|
||||
|
||||
async def test_sign_in_unknown_error(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, controller: MockHeos
|
||||
) -> None:
|
||||
"""Test sign-in service logs error for failure."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
controller.sign_in.side_effect = HeosError()
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_IN,
|
||||
{ATTR_USERNAME: "test@test.com", ATTR_PASSWORD: "password"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
controller.sign_in.assert_called_once_with("test@test.com", "password")
|
||||
|
||||
|
||||
async def test_sign_in_not_loaded_raises(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test the sign-in service when entry not loaded raises exception."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="The HEOS integration is not loaded"):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SIGN_IN,
|
||||
{ATTR_USERNAME: "test@test.com", ATTR_PASSWORD: "password"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
|
||||
async def test_sign_out(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, controller: MockHeos
|
||||
) -> None:
|
||||
"""Test the sign-out service."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||
|
||||
assert controller.sign_out.call_count == 1
|
||||
|
||||
|
||||
async def test_sign_out_not_loaded_raises(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test the sign-out service when entry not loaded raises exception."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="The HEOS integration is not loaded"):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||
|
||||
|
||||
async def test_sign_out_unknown_error(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, controller: MockHeos
|
||||
) -> None:
|
||||
"""Test the sign-out service."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
controller.sign_out.side_effect = HeosError()
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SIGN_OUT, {}, blocking=True)
|
||||
|
||||
assert controller.sign_out.call_count == 1
|
||||
Reference in New Issue
Block a user