1 """The soundtouch component."""
5 from libsoundtouch
import soundtouch_device
6 from libsoundtouch.device
import SoundTouchDevice
7 import voluptuous
as vol
17 SERVICE_ADD_ZONE_SLAVE,
19 SERVICE_PLAY_EVERYWHERE,
20 SERVICE_REMOVE_ZONE_SLAVE,
23 _LOGGER = logging.getLogger(__name__)
25 SERVICE_PLAY_EVERYWHERE_SCHEMA = vol.Schema({vol.Required(
"master"): cv.entity_id})
26 SERVICE_CREATE_ZONE_SCHEMA = vol.Schema(
28 vol.Required(
"master"): cv.entity_id,
29 vol.Required(
"slaves"): cv.entity_ids,
32 SERVICE_ADD_ZONE_SCHEMA = vol.Schema(
34 vol.Required(
"master"): cv.entity_id,
35 vol.Required(
"slaves"): cv.entity_ids,
38 SERVICE_REMOVE_ZONE_SCHEMA = vol.Schema(
40 vol.Required(
"master"): cv.entity_id,
41 vol.Required(
"slaves"): cv.entity_ids,
45 PLATFORMS = [Platform.MEDIA_PLAYER]
47 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
51 """SoundTouch data stored in the Home Assistant data object."""
53 def __init__(self, device: SoundTouchDevice) ->
None:
54 """Initialize the SoundTouch data object for a device."""
59 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
60 """Set up Bose SoundTouch component."""
63 """Handle the applying of a service."""
64 master_id = service.data.get(
"master")
65 slaves_ids = service.data.get(
"slaves")
70 for data
in hass.data[DOMAIN].values()
71 if data.media_player.entity_id
in slaves_ids
78 for data
in hass.data[DOMAIN].values()
79 if data.media_player.entity_id == master_id
86 _LOGGER.warning(
"Unable to find master with entity_id: %s",
str(master_id))
89 if service.service == SERVICE_PLAY_EVERYWHERE:
92 for data
in hass.data[DOMAIN].values()
93 if data.media_player.entity_id != master_id
95 await hass.async_add_executor_job(master.create_zone, slaves)
96 elif service.service == SERVICE_CREATE_ZONE:
97 await hass.async_add_executor_job(master.create_zone, slaves)
98 elif service.service == SERVICE_REMOVE_ZONE_SLAVE:
99 await hass.async_add_executor_job(master.remove_zone_slave, slaves)
100 elif service.service == SERVICE_ADD_ZONE_SLAVE:
101 await hass.async_add_executor_job(master.add_zone_slave, slaves)
103 hass.services.async_register(
105 SERVICE_PLAY_EVERYWHERE,
107 schema=SERVICE_PLAY_EVERYWHERE_SCHEMA,
109 hass.services.async_register(
113 schema=SERVICE_CREATE_ZONE_SCHEMA,
115 hass.services.async_register(
117 SERVICE_REMOVE_ZONE_SLAVE,
119 schema=SERVICE_REMOVE_ZONE_SCHEMA,
121 hass.services.async_register(
123 SERVICE_ADD_ZONE_SLAVE,
125 schema=SERVICE_ADD_ZONE_SCHEMA,
132 """Set up Bose SoundTouch from a config entry."""
133 device = await hass.async_add_executor_job(soundtouch_device, entry.data[CONF_HOST])
135 hass.data.setdefault(DOMAIN, {})[entry.entry_id] =
SoundTouchData(device)
137 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
142 """Unload a config entry."""
143 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
144 del hass.data[DOMAIN][entry.entry_id]
None __init__(self, SoundTouchDevice device)
def service_handle(HomeAssistant hass)
bool async_setup(HomeAssistant hass, ConfigType config)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)