⚠️ [working commit]: add configuration steps
This commit is contained in:
		
							parent
							
								
									7216766068
								
							
						
					
					
						commit
						00eccac431
					
				|  | @ -4,6 +4,11 @@ __pycache__/ | ||||||
| *$py.class | *$py.class | ||||||
| .DS_store | .DS_store | ||||||
| 
 | 
 | ||||||
|  | config | ||||||
|  | .vscode | ||||||
|  | .ruff_cache | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| # C extensions | # C extensions | ||||||
| *.so | *.so | ||||||
| .idea | .idea | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								CHANGELOG.md
								
								
								
								
							
							
						
						
									
										10
									
								
								CHANGELOG.md
								
								
								
								
							|  | @ -1,5 +1,15 @@ | ||||||
| # Changelog | # Changelog | ||||||
| 
 | 
 | ||||||
|  | ## [0.4.0] Add more fine grained configuration flow | ||||||
|  | 
 | ||||||
|  | ### Added | ||||||
|  | 
 | ||||||
|  | - Configuration flow options for enable / disable | ||||||
|  |   - "advanced audio" features (NightMode, Bassmode, VoiceEnhancer) | ||||||
|  |   - "woofer" feature | ||||||
|  |   - "soundmode" feature | ||||||
|  |   - "eq" feature | ||||||
|  | 
 | ||||||
| ## [0.3.2] Fix division by zero | ## [0.3.2] Fix division by zero | ||||||
| 
 | 
 | ||||||
| ### Added | ### Added | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								Pipfile
								
								
								
								
							
							
						
						
									
										2
									
								
								Pipfile
								
								
								
								
							|  | @ -13,4 +13,4 @@ black = "*" | ||||||
| isort = "*" | isort = "*" | ||||||
| 
 | 
 | ||||||
| [requires] | [requires] | ||||||
| python_version = "3.11" | python_version = "3.12" | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -6,9 +6,18 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||||
| from pysmartthings import SmartThings | from pysmartthings import SmartThings | ||||||
| 
 | 
 | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | from .api_extension.SoundbarDevice import SoundbarDevice | ||||||
| from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | from .const import ( | ||||||
|                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN, |     CONF_ENTRY_API_KEY, | ||||||
|                     SUPPORTED_DOMAINS) |     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, | ||||||
|  |     SUPPORTED_DOMAINS, | ||||||
|  | ) | ||||||
| from .models import DeviceConfig, SoundbarConfig | from .models import DeviceConfig, SoundbarConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
|  | @ -21,7 +30,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||||||
|     # store shell object |     # store shell object | ||||||
| 
 | 
 | ||||||
|     _LOGGER.info(f"[{DOMAIN}] Starting to setup a ConfigEntry") |     _LOGGER.info(f"[{DOMAIN}] Starting to setup a ConfigEntry") | ||||||
|     _LOGGER.debug(f"[{DOMAIN}] Setting up ConfigEntry with the following data: {entry.data}") |     _LOGGER.debug( | ||||||
|  |         f"[{DOMAIN}] Setting up ConfigEntry with the following data: {entry.data}" | ||||||
|  |     ) | ||||||
|     if not DOMAIN in hass.data: |     if not DOMAIN in hass.data: | ||||||
|         _LOGGER.debug(f"[{DOMAIN}] Domain not found in hass.data setting default") |         _LOGGER.debug(f"[{DOMAIN}] Domain not found in hass.data setting default") | ||||||
|         hass.data[DOMAIN] = SoundbarConfig( |         hass.data[DOMAIN] = SoundbarConfig( | ||||||
|  | @ -48,6 +59,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||||||
|             session, |             session, | ||||||
|             entry.data.get(CONF_ENTRY_MAX_VOLUME), |             entry.data.get(CONF_ENTRY_MAX_VOLUME), | ||||||
|             entry.data.get(CONF_ENTRY_DEVICE_NAME), |             entry.data.get(CONF_ENTRY_DEVICE_NAME), | ||||||
|  |             enable_eq=entry.data.get(CONF_ENTRY_SETTINGS_EQ_SELECTOR), | ||||||
|  |             enable_advanced_audio=entry.data.get( | ||||||
|  |                 CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES | ||||||
|  |             ), | ||||||
|  |             enable_soundmode=entry.data.get(CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR), | ||||||
|  |             enable_woofer=entry.data.get(CONF_ENTRY_SETTINGS_WOOFER_NUMBER), | ||||||
|         ) |         ) | ||||||
|         await soundbar_device.update() |         await soundbar_device.update() | ||||||
|         domain_config.devices[entry.data.get(CONF_ENTRY_DEVICE_ID)] = DeviceConfig( |         domain_config.devices[entry.data.get(CONF_ENTRY_DEVICE_ID)] = DeviceConfig( | ||||||
|  |  | ||||||
|  | @ -14,7 +14,15 @@ log = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
| class SoundbarDevice: | class SoundbarDevice: | ||||||
|     def __init__( |     def __init__( | ||||||
|         self, device: DeviceEntity, session, max_volume: int, device_name: str |         self, | ||||||
|  |         device: DeviceEntity, | ||||||
|  |         session, | ||||||
|  |         max_volume: int, | ||||||
|  |         device_name: str, | ||||||
|  |         enable_eq: bool = False, | ||||||
|  |         enable_soundmode: bool = False, | ||||||
|  |         enable_advanced_audio: bool = False, | ||||||
|  |         enable_woofer: bool = False, | ||||||
|     ): |     ): | ||||||
|         self.device = device |         self.device = device | ||||||
|         self._device_id = self.device.device_id |         self._device_id = self.device.device_id | ||||||
|  | @ -22,17 +30,21 @@ class SoundbarDevice: | ||||||
|         self.__session = session |         self.__session = session | ||||||
|         self.__device_name = device_name |         self.__device_name = device_name | ||||||
| 
 | 
 | ||||||
|  |         self.__enable_soundmode = enable_soundmode | ||||||
|         self.__supported_soundmodes = [] |         self.__supported_soundmodes = [] | ||||||
|         self.__active_soundmode = "" |         self.__active_soundmode = "" | ||||||
| 
 | 
 | ||||||
|  |         self.__enable_woofer = enable_woofer | ||||||
|         self.__woofer_level = 0 |         self.__woofer_level = 0 | ||||||
|         self.__woofer_connection = "" |         self.__woofer_connection = "" | ||||||
| 
 | 
 | ||||||
|  |         self.__enable_eq = enable_eq | ||||||
|         self.__active_eq_preset = "" |         self.__active_eq_preset = "" | ||||||
|         self.__supported_eq_presets = [] |         self.__supported_eq_presets = [] | ||||||
|         self.__eq_action = "" |         self.__eq_action = "" | ||||||
|         self.__eq_bands = [] |         self.__eq_bands = [] | ||||||
| 
 | 
 | ||||||
|  |         self.__enable_advanced_audio = enable_advanced_audio | ||||||
|         self.__voice_amplifier = 0 |         self.__voice_amplifier = 0 | ||||||
|         self.__night_mode = 0 |         self.__night_mode = 0 | ||||||
|         self.__bass_mode = 0 |         self.__bass_mode = 0 | ||||||
|  | @ -48,10 +60,13 @@ class SoundbarDevice: | ||||||
|     async def update(self): |     async def update(self): | ||||||
|         await self.device.status.refresh() |         await self.device.status.refresh() | ||||||
| 
 | 
 | ||||||
|         await self._update_media() |         if self.__enable_soundmode: | ||||||
|             await self._update_soundmode() |             await self._update_soundmode() | ||||||
|  |         if self.__enable_advanced_audio: | ||||||
|             await self._update_advanced_audio() |             await self._update_advanced_audio() | ||||||
|  |         if self.__enable_soundmode: | ||||||
|             await self._update_woofer() |             await self._update_woofer() | ||||||
|  |         if self.__enable_eq: | ||||||
|             await self._update_equalizer() |             await self._update_equalizer() | ||||||
| 
 | 
 | ||||||
|     async def _update_media(self): |     async def _update_media(self): | ||||||
|  | @ -70,14 +85,14 @@ class SoundbarDevice: | ||||||
| 
 | 
 | ||||||
|     async def _update_soundmode(self): |     async def _update_soundmode(self): | ||||||
|         await self.update_execution_data(["/sec/networkaudio/soundmode"]) |         await self.update_execution_data(["/sec/networkaudio/soundmode"]) | ||||||
|         await asyncio.sleep(0.1) |         await asyncio.sleep(1) | ||||||
|         payload = await self.get_execute_status() |         payload = await self.get_execute_status() | ||||||
|         retry = 0 |         retry = 0 | ||||||
|         while ( |         while ( | ||||||
|             "x.com.samsung.networkaudio.supportedSoundmode" not in payload |             "x.com.samsung.networkaudio.supportedSoundmode" not in payload | ||||||
|             and retry < 10 |             and retry < 10 | ||||||
|         ): |         ): | ||||||
|             await asyncio.sleep(0.2) |             await asyncio.sleep(1) | ||||||
|             payload = await self.get_execute_status() |             payload = await self.get_execute_status() | ||||||
|             retry += 1 |             retry += 1 | ||||||
|         if retry == 10: |         if retry == 10: | ||||||
|  | @ -376,7 +391,8 @@ class SoundbarDevice: | ||||||
|     # ------------ SUPPORT FUNCTIONS ------------ |     # ------------ SUPPORT FUNCTIONS ------------ | ||||||
| 
 | 
 | ||||||
|     async def update_execution_data(self, argument: str): |     async def update_execution_data(self, argument: str): | ||||||
|         return await self.device.command("main", "execute", "execute", argument) |         stuff = await self.device.command("main", "execute", "execute", argument) | ||||||
|  |         return stuff | ||||||
| 
 | 
 | ||||||
|     async def set_custom_execution_data(self, href: str, property: str, value): |     async def set_custom_execution_data(self, href: str, property: str, value): | ||||||
|         argument = [href, {property: value}] |         argument = [href, {property: value}] | ||||||
|  | @ -386,8 +402,8 @@ class SoundbarDevice: | ||||||
|         url = f"https://api.smartthings.com/v1/devices/{self._device_id}/components/main/capabilities/execute/status" |         url = f"https://api.smartthings.com/v1/devices/{self._device_id}/components/main/capabilities/execute/status" | ||||||
|         request_headers = {"Authorization": "Bearer " + self._api_key} |         request_headers = {"Authorization": "Bearer " + self._api_key} | ||||||
|         resp = await self.__session.get(url, headers=request_headers) |         resp = await self.__session.get(url, headers=request_headers) | ||||||
|         dict = await resp.json() |         dict_stuff = await resp.json() | ||||||
|         return dict["data"]["value"]["payload"] |         return dict_stuff["data"]["value"]["payload"] | ||||||
| 
 | 
 | ||||||
|     async def get_song_title_artwork(self, artist: str, title: str) -> str: |     async def get_song_title_artwork(self, artist: str, title: str) -> str: | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| import logging | import logging | ||||||
|  | from typing import Any | ||||||
| 
 | 
 | ||||||
| import pysmartthings | import pysmartthings | ||||||
| import voluptuous as vol | import voluptuous as vol | ||||||
|  | @ -7,8 +8,17 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||||
| from pysmartthings import APIResponseError | from pysmartthings import APIResponseError | ||||||
| from voluptuous import All, Range | from voluptuous import All, Range | ||||||
| 
 | 
 | ||||||
| from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | from .const import ( | ||||||
|                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) |     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, | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  | @ -24,20 +34,8 @@ async def validate_input(api, device_id: str): | ||||||
| class ExampleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | class ExampleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||||||
|     async def async_step_user(self, user_input=None): |     async def async_step_user(self, user_input=None): | ||||||
|         if user_input is not None: |         if user_input is not None: | ||||||
|             try: |             self.user_input = user_input | ||||||
|                 session = async_get_clientsession(self.hass) |             return await self.async_step_device() | ||||||
|                 api = pysmartthings.SmartThings( |  | ||||||
|                     session, user_input.get(CONF_ENTRY_API_KEY) |  | ||||||
|                 ) |  | ||||||
|                 device = await validate_input(api, user_input.get(CONF_ENTRY_DEVICE_ID)) |  | ||||||
| 
 |  | ||||||
|                 _LOGGER.debug( |  | ||||||
|                     f"Successfully validated Input, Creating entry with title {DOMAIN} and data {user_input}" |  | ||||||
|                 ) |  | ||||||
|                 return self.async_create_entry(title=DOMAIN, data=user_input) |  | ||||||
|             except Exception as excp: |  | ||||||
|                 _LOGGER.error(f"The ConfigFlow triggered an exception {excp}") |  | ||||||
|                 return self.async_abort(reason="fetch_failed") |  | ||||||
| 
 | 
 | ||||||
|         return self.async_show_form( |         return self.async_show_form( | ||||||
|             step_id="user", |             step_id="user", | ||||||
|  | @ -46,7 +44,98 @@ class ExampleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||||||
|                     vol.Required(CONF_ENTRY_API_KEY): str, |                     vol.Required(CONF_ENTRY_API_KEY): str, | ||||||
|                     vol.Required(CONF_ENTRY_DEVICE_ID): str, |                     vol.Required(CONF_ENTRY_DEVICE_ID): str, | ||||||
|                     vol.Required(CONF_ENTRY_DEVICE_NAME): str, |                     vol.Required(CONF_ENTRY_DEVICE_NAME): str, | ||||||
|                     vol.Required(CONF_ENTRY_MAX_VOLUME, default=100): All(int, Range(min=1, max=100)) |                     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) | ||||||
|  | 
 | ||||||
|  |             try: | ||||||
|  |                 session = async_get_clientsession(self.hass) | ||||||
|  |                 api = pysmartthings.SmartThings( | ||||||
|  |                     session, self.user_input.get(CONF_ENTRY_API_KEY) | ||||||
|  |                 ) | ||||||
|  |                 device = await validate_input( | ||||||
|  |                     api, self.user_input.get(CONF_ENTRY_DEVICE_ID) | ||||||
|  |                 ) | ||||||
|  |                 _LOGGER.debug( | ||||||
|  |                     f"Successfully validated Input, Creating entry with title {DOMAIN} and data {user_input}" | ||||||
|  |                 ) | ||||||
|  |             except Exception as excp: | ||||||
|  |                 _LOGGER.error(f"The ConfigFlow triggered an exception {excp}") | ||||||
|  |                 return self.async_abort(reason="fetch_failed") | ||||||
|  |             return self.async_create_entry(title=DOMAIN, data=self.user_input) | ||||||
|  | 
 | ||||||
|  |         return self.async_show_form( | ||||||
|  |             step_id="device", | ||||||
|  |             data_schema=vol.Schema( | ||||||
|  |                 { | ||||||
|  |                     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) | ||||||
|  |                     ), | ||||||
|  |                 } | ||||||
|  |             ), | ||||||
|  |             errors=errors, | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  | @ -9,6 +9,12 @@ CONF_ENTRY_API_KEY = "api_key" | ||||||
| CONF_ENTRY_DEVICE_ID = "device_id" | CONF_ENTRY_DEVICE_ID = "device_id" | ||||||
| CONF_ENTRY_DEVICE_NAME = "device_name" | CONF_ENTRY_DEVICE_NAME = "device_name" | ||||||
| CONF_ENTRY_MAX_VOLUME = "device_volume" | CONF_ENTRY_MAX_VOLUME = "device_volume" | ||||||
|  | 
 | ||||||
|  | CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES = "settings_advanced_audio" | ||||||
|  | CONF_ENTRY_SETTINGS_EQ_SELECTOR = "settings_eq" | ||||||
|  | CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR = "settings_soundmode" | ||||||
|  | CONF_ENTRY_SETTINGS_WOOFER_NUMBER = "settings_woofer" | ||||||
|  | 
 | ||||||
| DEFAULT_NAME = DOMAIN | DEFAULT_NAME = DOMAIN | ||||||
| 
 | 
 | ||||||
| BUTTON = BUTTON_DOMAIN | BUTTON = BUTTON_DOMAIN | ||||||
|  |  | ||||||
|  | @ -8,5 +8,5 @@ | ||||||
|   "iot_class": "cloud_polling", |   "iot_class": "cloud_polling", | ||||||
|   "issue_tracker": "https://github.com/samuelspagl/ha_samsung_soundbar/issues", |   "issue_tracker": "https://github.com/samuelspagl/ha_samsung_soundbar/issues", | ||||||
|   "requirements": ["pysmartthings"], |   "requirements": ["pysmartthings"], | ||||||
|   "version": "0.3.2" |   "version": "0.4.0" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,16 +1,22 @@ | ||||||
| import logging | import logging | ||||||
| from typing import Any, Mapping | from typing import Any, Mapping | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.media_player import (DEVICE_CLASS_SPEAKER, | from homeassistant.components.media_player import ( | ||||||
|                                                    MediaPlayerEntity) |     DEVICE_CLASS_SPEAKER, | ||||||
| from homeassistant.components.media_player.const import \ |     MediaPlayerEntity, | ||||||
|     MediaPlayerEntityFeature | ) | ||||||
|  | from homeassistant.components.media_player.const import MediaPlayerEntityFeature | ||||||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||||
| from homeassistant.helpers.entity import DeviceInfo, generate_entity_id | from homeassistant.helpers.entity import DeviceInfo, generate_entity_id | ||||||
| 
 | 
 | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | from .api_extension.SoundbarDevice import SoundbarDevice | ||||||
| from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | from .const import ( | ||||||
|                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) |     CONF_ENTRY_API_KEY, | ||||||
|  |     CONF_ENTRY_DEVICE_ID, | ||||||
|  |     CONF_ENTRY_DEVICE_NAME, | ||||||
|  |     CONF_ENTRY_MAX_VOLUME, | ||||||
|  |     DOMAIN, | ||||||
|  | ) | ||||||
| from .models import DeviceConfig | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
|  |  | ||||||
|  | @ -1,12 +1,14 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.number import (NumberEntity, | from homeassistant.components.number import ( | ||||||
|  |     NumberEntity, | ||||||
|     NumberEntityDescription, |     NumberEntityDescription, | ||||||
|                                              NumberMode) |     NumberMode, | ||||||
|  | ) | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | from .api_extension.SoundbarDevice import SoundbarDevice | ||||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | from .const import CONF_ENTRY_DEVICE_ID, CONF_ENTRY_SETTINGS_WOOFER_NUMBER, DOMAIN | ||||||
| from .models import DeviceConfig | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
|  | @ -19,7 +21,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|     for key in domain_data.devices: |     for key in domain_data.devices: | ||||||
|         device_config: DeviceConfig = domain_data.devices[key] |         device_config: DeviceConfig = domain_data.devices[key] | ||||||
|         device = device_config.device |         device = device_config.device | ||||||
|         if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID): |         if device.device_id == config_entry.data.get( | ||||||
|  |             CONF_ENTRY_DEVICE_ID | ||||||
|  |         ) and config_entry.data.get(CONF_ENTRY_SETTINGS_WOOFER_NUMBER): | ||||||
|             entities.append( |             entities.append( | ||||||
|                 SoundbarWooferNumberEntity( |                 SoundbarWooferNumberEntity( | ||||||
|                     device, |                     device, | ||||||
|  |  | ||||||
|  | @ -1,14 +1,20 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.number import (NumberEntity, | from homeassistant.components.number import ( | ||||||
|  |     NumberEntity, | ||||||
|     NumberEntityDescription, |     NumberEntityDescription, | ||||||
|                                              NumberMode) |     NumberMode, | ||||||
| from homeassistant.components.select import (SelectEntity, | ) | ||||||
|                                              SelectEntityDescription) | from homeassistant.components.select import SelectEntity, SelectEntityDescription | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | from .api_extension.SoundbarDevice import SoundbarDevice | ||||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | from .const import ( | ||||||
|  |     CONF_ENTRY_DEVICE_ID, | ||||||
|  |     CONF_ENTRY_SETTINGS_EQ_SELECTOR, | ||||||
|  |     CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR, | ||||||
|  |     DOMAIN, | ||||||
|  | ) | ||||||
| from .models import DeviceConfig | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
|  | @ -21,12 +27,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|         device_config: DeviceConfig = domain_data.devices[key] |         device_config: DeviceConfig = domain_data.devices[key] | ||||||
|         device = device_config.device |         device = device_config.device | ||||||
|         if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID): |         if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID): | ||||||
|  |             if config_entry.data.get(CONF_ENTRY_SETTINGS_EQ_SELECTOR): | ||||||
|                 entities.append( |                 entities.append( | ||||||
|                     EqPresetSelectEntity(device, "eq_preset", "mdi:tune-vertical") |                     EqPresetSelectEntity(device, "eq_preset", "mdi:tune-vertical") | ||||||
|                 ) |                 ) | ||||||
|  |             if config_entry.data.get(CONF_ENTRY_SETTINGS_SOUNDMODE_SELECTOR): | ||||||
|                 entities.append( |                 entities.append( | ||||||
|                 SoundModeSelectEntity(device, "sound_mode_preset", "mdi:surround-sound") |                     SoundModeSelectEntity( | ||||||
|  |                         device, "sound_mode_preset", "mdi:surround-sound" | ||||||
|                     ) |                     ) | ||||||
|  |                 ) | ||||||
|  | 
 | ||||||
|             entities.append( |             entities.append( | ||||||
|                 InputSelectEntity(device, "input_preset", "mdi:video-input-hdmi") |                 InputSelectEntity(device, "input_preset", "mdi:video-input-hdmi") | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|  | @ -1,7 +1,10 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity, | from homeassistant.components.sensor import ( | ||||||
|                                              SensorStateClass) |     SensorDeviceClass, | ||||||
|  |     SensorEntity, | ||||||
|  |     SensorStateClass, | ||||||
|  | ) | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | from .api_extension.SoundbarDevice import SoundbarDevice | ||||||
|  |  | ||||||
|  | @ -4,7 +4,11 @@ from homeassistant.components.switch import SwitchEntity | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | from .api_extension.SoundbarDevice import SoundbarDevice | ||||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | from .const import ( | ||||||
|  |     CONF_ENTRY_DEVICE_ID, | ||||||
|  |     CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES, | ||||||
|  |     DOMAIN, | ||||||
|  | ) | ||||||
| from .models import DeviceConfig | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
|  | @ -18,6 +22,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|         device_config: DeviceConfig = domain_data.devices[key] |         device_config: DeviceConfig = domain_data.devices[key] | ||||||
|         device = device_config.device |         device = device_config.device | ||||||
|         if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID): |         if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID): | ||||||
|  |             if config_entry.data.get(CONF_ENTRY_SETTINGS_ADVANCED_AUDIO_SWITCHES): | ||||||
|                 entities.append( |                 entities.append( | ||||||
|                     SoundbarSwitchAdvancedAudio( |                     SoundbarSwitchAdvancedAudio( | ||||||
|                         device, |                         device, | ||||||
|  |  | ||||||
|  | @ -10,6 +10,27 @@ | ||||||
|                   }, |                   }, | ||||||
|                   "description": "Bitte gib deine Daten ein.", |                   "description": "Bitte gib deine Daten ein.", | ||||||
|                   "title": "Authentifizierung" |                   "title": "Authentifizierung" | ||||||
|  |             }, | ||||||
|  |             "device":{ | ||||||
|  |                 "data" : { | ||||||
|  |                     "settings_advanced_audio": "'Advanced Audio switches' aktivieren (NightMode, BassMode, VoiceEnhancer)", | ||||||
|  |                     "settings_eq": "'EQ selector' aktivieren", | ||||||
|  |                     "settings_soundmode": "'Soundmode selector' aktivieren", | ||||||
|  |                     "settings_woofer": "'Subwoofer Entität' aktivieren" | ||||||
|  |                 }, | ||||||
|  |                 "description": "Einige Soundbars haben verschiedene Featuresets. Wähle bitte aus welche Features von deiner Soundbar supported werden (einsehbar in der SmartThings App).", | ||||||
|  |                 "title": "Geräte Einstellungen" | ||||||
|  |             }, | ||||||
|  |             "reconfigure_confirm":{ | ||||||
|  |                 "data" : { | ||||||
|  |                     "settings_advanced_audio": "'Advanced Audio switches' aktivieren (NightMode, BassMode, VoiceEnhancer)", | ||||||
|  |                     "settings_eq": "'EQ selector' aktivieren", | ||||||
|  |                     "settings_soundmode": "'Soundmode selector' aktivieren", | ||||||
|  |                     "settings_woofer": "'Subwoofer Entität' aktivieren", | ||||||
|  |                     "device_volume": "Max Volume (int)" | ||||||
|  |                 }, | ||||||
|  |                 "description": "Einige Soundbars haben verschiedene Featuresets. Wähle bitte aus welche Features von deiner Soundbar supported werden (einsehbar in der SmartThings App).", | ||||||
|  |                 "title": "Geräte Einstellungen" | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -10,6 +10,27 @@ | ||||||
|                   }, |                   }, | ||||||
|                   "description": "Please enter your credentials.", |                   "description": "Please enter your credentials.", | ||||||
|                   "title": "Authentication" |                   "title": "Authentication" | ||||||
|  |             }, | ||||||
|  |             "device":{ | ||||||
|  |                 "data" : { | ||||||
|  |                     "settings_advanced_audio": "Enable 'Advanced Audio switches' capabilities (NightMode, BassMode, VoiceEnhancer)", | ||||||
|  |                     "settings_eq": "Enable 'EQ selector' capabilities", | ||||||
|  |                     "settings_soundmode": "Enable 'Soundmode selector' capabilities", | ||||||
|  |                     "settings_woofer": "Enable 'Woofer number' capability" | ||||||
|  |                 }, | ||||||
|  |                 "description": "Some soundbars have a different featureset than others. Please the features supported by your soundbar (visible in the SmartThings App).", | ||||||
|  |                 "title": "Device Settings" | ||||||
|  |             }, | ||||||
|  |             "reconfigure_confirm":{ | ||||||
|  |                 "data" : { | ||||||
|  |                     "settings_advanced_audio": "Enable 'Advanced Audio switches' capabilities (NightMode, BassMode, VoiceEnhancer)", | ||||||
|  |                     "settings_eq": "Enable 'EQ selector' capabilities", | ||||||
|  |                     "settings_soundmode": "Enable 'Soundmode selector' capabilities", | ||||||
|  |                     "settings_woofer": "Enable 'Woofer number' capability", | ||||||
|  |                     "device_volume": "Max Volume (int)" | ||||||
|  |                 }, | ||||||
|  |                 "description": "Some soundbars have a different featureset than others. Please the features supported by your soundbar (visible in the SmartThings App).", | ||||||
|  |                 "title": "Device Settings" | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue