2023-09-06 18:20:27 +03:00
|
|
|
import logging
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
from typing import Any
|
2023-09-06 18:20:27 +03:00
|
|
|
|
|
|
|
import pysmartthings
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from pysmartthings import APIResponseError
|
2024-04-01 11:49:48 +03:00
|
|
|
from voluptuous import All, Range
|
2023-09-06 18:20:27 +03:00
|
|
|
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
from .const import (
|
|
|
|
CONF_ENTRY_API_KEY,
|
|
|
|
CONF_ENTRY_DEVICE_ID,
|
|
|
|
CONF_ENTRY_DEVICE_NAME,
|
|
|
|
CONF_ENTRY_MAX_VOLUME,
|
|
|
|
CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES,
|
|
|
|
CONF_ENTRY_SETTINGS_EQ_SELECTOR,
|
|
|
|
CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR,
|
|
|
|
CONF_ENTRY_SETTINGS_WOOFER_NUMBER,
|
|
|
|
DOMAIN,
|
|
|
|
)
|
2023-09-06 18:20:27 +03:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
async def validate_input(api, device_id: str):
|
|
|
|
try:
|
|
|
|
return await api.device(device_id)
|
|
|
|
except APIResponseError as excp:
|
|
|
|
_LOGGER.error("[Samsung Soundbar] ERROR: %s", str(excp))
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|
|
|
async def async_step_user(self, user_input=None):
|
|
|
|
if user_input is not None:
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
self.user_input = user_input
|
|
|
|
return await self.async_step_device()
|
|
|
|
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="user",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_ENTRY_API_KEY): str,
|
|
|
|
vol.Required(CONF_ENTRY_DEVICE_ID): str,
|
|
|
|
vol.Required(CONF_ENTRY_DEVICE_NAME): str,
|
|
|
|
vol.Required(CONF_ENTRY_MAX_VOLUME, default=100): All(
|
|
|
|
int, Range(min=1, max=100)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
async def async_step_device(self, user_input: dict[str, any] | None = None):
|
|
|
|
if user_input is not None:
|
|
|
|
self.user_input.update(user_input)
|
|
|
|
|
2023-09-06 18:20:27 +03:00
|
|
|
try:
|
|
|
|
session = async_get_clientsession(self.hass)
|
|
|
|
api = pysmartthings.SmartThings(
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
session, self.user_input.get(CONF_ENTRY_API_KEY)
|
|
|
|
)
|
|
|
|
device = await validate_input(
|
|
|
|
api, self.user_input.get(CONF_ENTRY_DEVICE_ID)
|
2023-09-06 18:20:27 +03:00
|
|
|
)
|
2024-03-12 16:39:12 +03:00
|
|
|
_LOGGER.debug(
|
2023-09-06 18:20:27 +03:00
|
|
|
f"Successfully validated Input, Creating entry with title {DOMAIN} and data {user_input}"
|
|
|
|
)
|
|
|
|
except Exception as excp:
|
2024-03-12 16:39:12 +03:00
|
|
|
_LOGGER.error(f"The ConfigFlow triggered an exception {excp}")
|
2023-09-06 18:20:27 +03:00
|
|
|
return self.async_abort(reason="fetch_failed")
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
return self.async_create_entry(title=DOMAIN, data=self.user_input)
|
2023-09-06 18:20:27 +03:00
|
|
|
|
|
|
|
return self.async_show_form(
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
step_id="device",
|
2023-09-06 18:20:27 +03:00
|
|
|
data_schema=vol.Schema(
|
|
|
|
{
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
vol.Required(CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES): bool,
|
|
|
|
vol.Required(CONF_ENTRY_SETTINGS_EQ_SELECTOR): bool,
|
|
|
|
vol.Required(CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR): bool,
|
|
|
|
vol.Required(CONF_ENTRY_SETTINGS_WOOFER_NUMBER): bool,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None):
|
|
|
|
"""Handle a reconfiguration flow initialized by the user."""
|
|
|
|
self.config_entry = self.hass.config_entries.async_get_entry(
|
|
|
|
self.context["entry_id"]
|
|
|
|
)
|
|
|
|
return await self.async_step_reconfigure_confirm()
|
|
|
|
|
|
|
|
async def async_step_reconfigure_confirm(
|
|
|
|
self, user_input: dict[str, Any] | None = None
|
|
|
|
):
|
|
|
|
"""Handle a reconfiguration flow initialized by the user."""
|
|
|
|
errors: dict[str, str] = {}
|
|
|
|
assert self.config_entry
|
|
|
|
|
|
|
|
if user_input is not None:
|
|
|
|
return self.async_update_reload_and_abort(
|
|
|
|
self.config_entry,
|
|
|
|
data={**self.config_entry.data, **user_input},
|
|
|
|
reason="reconfigure_successful",
|
|
|
|
)
|
|
|
|
|
|
|
|
return self.async_show_form(
|
|
|
|
step_id="reconfigure_confirm",
|
|
|
|
data_schema=vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(
|
|
|
|
CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES,
|
|
|
|
default=self.config_entry.data.get(
|
|
|
|
CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES
|
|
|
|
),
|
|
|
|
): bool,
|
|
|
|
vol.Required(
|
|
|
|
CONF_ENTRY_SETTINGS_EQ_SELECTOR,
|
|
|
|
default=self.config_entry.data.get(
|
|
|
|
CONF_ENTRY_SETTINGS_EQ_SELECTOR
|
|
|
|
),
|
|
|
|
): bool,
|
|
|
|
vol.Required(
|
|
|
|
CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR,
|
|
|
|
default=self.config_entry.data.get(
|
|
|
|
CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR
|
|
|
|
),
|
|
|
|
): bool,
|
|
|
|
vol.Required(
|
|
|
|
CONF_ENTRY_SETTINGS_WOOFER_NUMBER,
|
|
|
|
default=self.config_entry.data.get(
|
|
|
|
CONF_ENTRY_SETTINGS_WOOFER_NUMBER
|
|
|
|
),
|
|
|
|
): bool,
|
|
|
|
vol.Required(CONF_ENTRY_MAX_VOLUME, default=100): All(
|
|
|
|
int, Range(min=1, max=100)
|
|
|
|
),
|
2023-09-06 18:20:27 +03:00
|
|
|
}
|
|
|
|
),
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
errors=errors,
|
2023-09-06 18:20:27 +03:00
|
|
|
)
|