Compare commits
	
		
			2 Commits
		
	
	
		
			main
			...
			chore/lint
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | 79ff789611 | |
|  | dd04d8f0d4 | 
|  | @ -1,5 +1,11 @@ | |||
| # Changelog | ||||
| 
 | ||||
| ## [0.2.1] Chore: Format repository - 2024-02-08 | ||||
| 
 | ||||
| ### Changed | ||||
| 
 | ||||
| - formatted the repository with black and isort | ||||
| 
 | ||||
| ## [0.2.0] Add volume sensor - 2024-02-08 | ||||
| 
 | ||||
| ### Added | ||||
|  |  | |||
|  | @ -1,14 +1,17 @@ | |||
| import asyncio | ||||
| import datetime | ||||
| import json | ||||
| import logging | ||||
| import time | ||||
| from urllib.parse import quote | ||||
| import logging | ||||
| 
 | ||||
| from pysmartthings import DeviceEntity | ||||
| 
 | ||||
| from ..const import DOMAIN | ||||
| 
 | ||||
| log = logging.getLogger(__name__) | ||||
| 
 | ||||
| 
 | ||||
| class SoundbarDevice: | ||||
|     def __init__( | ||||
|         self, device: DeviceEntity, session, max_volume: int, device_name: str | ||||
|  | @ -70,12 +73,17 @@ class SoundbarDevice: | |||
|         await asyncio.sleep(0.1) | ||||
|         payload = await self.get_execute_status() | ||||
|         retry = 0 | ||||
|         while("x.com.samsung.networkaudio.supportedSoundmode" not in payload and retry < 10): | ||||
|         while ( | ||||
|             "x.com.samsung.networkaudio.supportedSoundmode" not in payload | ||||
|             and retry < 10 | ||||
|         ): | ||||
|             await asyncio.sleep(0.2) | ||||
|             payload = await self.get_execute_status() | ||||
|             retry += 1 | ||||
|         if retry == 10: | ||||
|             log.error(f"[{DOMAIN}] Error: _update_soundmode exceeded a retry counter of 10") | ||||
|             log.error( | ||||
|                 f"[{DOMAIN}] Error: _update_soundmode exceeded a retry counter of 10" | ||||
|             ) | ||||
|             return | ||||
| 
 | ||||
|         self.__supported_soundmodes = payload[ | ||||
|  | @ -88,12 +96,14 @@ class SoundbarDevice: | |||
|         await asyncio.sleep(0.1) | ||||
|         payload = await self.get_execute_status() | ||||
|         retry = 0 | ||||
|         while("x.com.samsung.networkaudio.woofer" not in payload and retry < 10): | ||||
|         while "x.com.samsung.networkaudio.woofer" not in payload and retry < 10: | ||||
|             await asyncio.sleep(0.2) | ||||
|             payload = await self.get_execute_status() | ||||
|             retry += 1 | ||||
|         if retry == 10: | ||||
|             log.error(f"[{DOMAIN}] Error: _update_woofer exceeded a retry counter of 10") | ||||
|             log.error( | ||||
|                 f"[{DOMAIN}] Error: _update_woofer exceeded a retry counter of 10" | ||||
|             ) | ||||
|             return | ||||
|         self.__woofer_level = payload["x.com.samsung.networkaudio.woofer"] | ||||
|         self.__woofer_connection = payload["x.com.samsung.networkaudio.connection"] | ||||
|  | @ -103,12 +113,14 @@ class SoundbarDevice: | |||
|         await asyncio.sleep(0.1) | ||||
|         payload = await self.get_execute_status() | ||||
|         retry = 0 | ||||
|         while("x.com.samsung.networkaudio.EQname" not in payload and retry < 10): | ||||
|         while "x.com.samsung.networkaudio.EQname" not in payload and retry < 10: | ||||
|             await asyncio.sleep(0.2) | ||||
|             payload = await self.get_execute_status() | ||||
|             retry += 1 | ||||
|         if retry == 10: | ||||
|             log.error(f"[{DOMAIN}] Error: _update_equalizer exceeded a retry counter of 10") | ||||
|             log.error( | ||||
|                 f"[{DOMAIN}] Error: _update_equalizer exceeded a retry counter of 10" | ||||
|             ) | ||||
|             return | ||||
|         self.__active_eq_preset = payload["x.com.samsung.networkaudio.EQname"] | ||||
|         self.__supported_eq_presets = payload[ | ||||
|  | @ -123,12 +135,14 @@ class SoundbarDevice: | |||
| 
 | ||||
|         payload = await self.get_execute_status() | ||||
|         retry = 0 | ||||
|         while("x.com.samsung.networkaudio.nightmode" not in payload and retry < 10): | ||||
|         while "x.com.samsung.networkaudio.nightmode" not in payload and retry < 10: | ||||
|             await asyncio.sleep(0.2) | ||||
|             payload = await self.get_execute_status() | ||||
|             retry += 1 | ||||
|         if retry == 10: | ||||
|             log.error(f"[{DOMAIN}] Error: _update_advanced_audio exceeded a retry counter of 10") | ||||
|             log.error( | ||||
|                 f"[{DOMAIN}] Error: _update_advanced_audio exceeded a retry counter of 10" | ||||
|             ) | ||||
|             return | ||||
| 
 | ||||
|         self.__night_mode = payload["x.com.samsung.networkaudio.nightmode"] | ||||
|  |  | |||
|  | @ -6,13 +6,8 @@ from homeassistant import config_entries | |||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||
| from pysmartthings import APIResponseError | ||||
| 
 | ||||
| from .const import ( | ||||
|     CONF_ENTRY_API_KEY, | ||||
|     CONF_ENTRY_DEVICE_ID, | ||||
|     CONF_ENTRY_DEVICE_NAME, | ||||
|     CONF_ENTRY_MAX_VOLUME, | ||||
|     DOMAIN, | ||||
| ) | ||||
| from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | ||||
|                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,9 +6,9 @@ from homeassistant.core import HomeAssistant | |||
| from homeassistant.helpers.entity import DeviceInfo | ||||
| from homeassistant.helpers.typing import UndefinedType | ||||
| 
 | ||||
| from .models import DeviceConfig | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import DOMAIN, CONF_ENTRY_DEVICE_ID | ||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | ||||
| from .models import DeviceConfig | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,33 +1,18 @@ | |||
| import logging | ||||
| from typing import Any, Mapping | ||||
| 
 | ||||
| from homeassistant.components.media_player import ( | ||||
|     DEVICE_CLASS_SPEAKER, | ||||
|     MediaPlayerEntity, | ||||
| ) | ||||
| from homeassistant.components.media_player import (DEVICE_CLASS_SPEAKER, | ||||
|                                                    MediaPlayerEntity) | ||||
| from homeassistant.components.media_player.const import ( | ||||
|     SUPPORT_PAUSE, | ||||
|     SUPPORT_PLAY, | ||||
|     SUPPORT_SELECT_SOUND_MODE, | ||||
|     SUPPORT_SELECT_SOURCE, | ||||
|     SUPPORT_STOP, | ||||
|     SUPPORT_TURN_OFF, | ||||
|     SUPPORT_TURN_ON, | ||||
|     SUPPORT_VOLUME_MUTE, | ||||
|     SUPPORT_VOLUME_SET, | ||||
|     SUPPORT_VOLUME_STEP, | ||||
| ) | ||||
|     SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_SELECT_SOUND_MODE, | ||||
|     SUPPORT_SELECT_SOURCE, SUPPORT_STOP, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, | ||||
|     SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_VOLUME_STEP) | ||||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||
| from homeassistant.helpers.entity import DeviceInfo, generate_entity_id | ||||
| 
 | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import ( | ||||
|     CONF_ENTRY_API_KEY, | ||||
|     CONF_ENTRY_DEVICE_ID, | ||||
|     CONF_ENTRY_DEVICE_NAME, | ||||
|     CONF_ENTRY_MAX_VOLUME, | ||||
|     DOMAIN, | ||||
| ) | ||||
| from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | ||||
|                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) | ||||
| from .models import DeviceConfig | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
|  |  | |||
|  | @ -1,11 +1,13 @@ | |||
| import logging | ||||
| 
 | ||||
| from homeassistant.components.number import NumberEntity, NumberEntityDescription, NumberMode | ||||
| from homeassistant.components.number import (NumberEntity, | ||||
|                                              NumberEntityDescription, | ||||
|                                              NumberMode) | ||||
| from homeassistant.helpers.entity import DeviceInfo | ||||
| 
 | ||||
| from .models import DeviceConfig | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | ||||
| from .models import DeviceConfig | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
| 
 | ||||
|  | @ -35,13 +37,14 @@ class SoundbarWooferNumberEntity(NumberEntity): | |||
|         append_unique_id: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = NumberEntityDescription(native_max_value=6, | ||||
|                                                           native_min_value=-10, | ||||
|                                                           mode=NumberMode.BOX, | ||||
|                                                           native_step=1, | ||||
|                                                           native_unit_of_measurement="dB", | ||||
|                                                           key=append_unique_id, | ||||
|                                                           ) | ||||
|         self.entity_description = NumberEntityDescription( | ||||
|             native_max_value=6, | ||||
|             native_min_value=-10, | ||||
|             mode=NumberMode.BOX, | ||||
|             native_step=1, | ||||
|             native_unit_of_measurement="dB", | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  |  | |||
|  | @ -1,12 +1,15 @@ | |||
| import logging | ||||
| 
 | ||||
| from homeassistant.components.number import NumberEntity, NumberEntityDescription, NumberMode | ||||
| from homeassistant.components.select import SelectEntityDescription, SelectEntity | ||||
| from homeassistant.components.number import (NumberEntity, | ||||
|                                              NumberEntityDescription, | ||||
|                                              NumberMode) | ||||
| from homeassistant.components.select import (SelectEntity, | ||||
|                                              SelectEntityDescription) | ||||
| from homeassistant.helpers.entity import DeviceInfo | ||||
| 
 | ||||
| from .models import DeviceConfig | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | ||||
| from .models import DeviceConfig | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
| 
 | ||||
|  | @ -42,13 +45,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | |||
| 
 | ||||
| class EqPresetSelectEntity(SelectEntity): | ||||
|     def __init__( | ||||
|             self, | ||||
|             device: SoundbarDevice, | ||||
|             append_unique_id: str, | ||||
|         self, | ||||
|         device: SoundbarDevice, | ||||
|         append_unique_id: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = SelectEntityDescription(key=append_unique_id, | ||||
|                                                           ) | ||||
|         self.entity_description = SelectEntityDescription( | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  | @ -83,13 +87,14 @@ class EqPresetSelectEntity(SelectEntity): | |||
| 
 | ||||
| class SoundModeSelectEntity(SelectEntity): | ||||
|     def __init__( | ||||
|             self, | ||||
|             device: SoundbarDevice, | ||||
|             append_unique_id: str, | ||||
|         self, | ||||
|         device: SoundbarDevice, | ||||
|         append_unique_id: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = SelectEntityDescription(key=append_unique_id, | ||||
|                                                           ) | ||||
|         self.entity_description = SelectEntityDescription( | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  | @ -124,13 +129,14 @@ class SoundModeSelectEntity(SelectEntity): | |||
| 
 | ||||
| class InputSelectEntity(SelectEntity): | ||||
|     def __init__( | ||||
|             self, | ||||
|             device: SoundbarDevice, | ||||
|             append_unique_id: str, | ||||
|         self, | ||||
|         device: SoundbarDevice, | ||||
|         append_unique_id: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = SelectEntityDescription(key=append_unique_id, | ||||
|                                                           ) | ||||
|         self.entity_description = SelectEntityDescription( | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  |  | |||
|  | @ -1,14 +1,16 @@ | |||
| import logging | ||||
| 
 | ||||
| from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass | ||||
| 
 | ||||
| from .models import DeviceConfig | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | ||||
| from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity, | ||||
|                                              SensorStateClass) | ||||
| from homeassistant.helpers.entity import DeviceInfo | ||||
| 
 | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | ||||
| from .models import DeviceConfig | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
| 
 | ||||
| 
 | ||||
| async def async_setup_entry(hass, config_entry, async_add_entities): | ||||
|     domain_data = hass.data[DOMAIN] | ||||
|     entities = [] | ||||
|  | @ -17,14 +19,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | |||
|         device = device_config.device | ||||
| 
 | ||||
|         if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID): | ||||
|             entities.append( | ||||
|                 VolumeSensor(device, "volume_level") | ||||
|             ) | ||||
|             entities.append(VolumeSensor(device, "volume_level")) | ||||
|     async_add_entities(entities) | ||||
|     return True | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class VolumeSensor(SensorEntity): | ||||
|     def __init__(self, device: SoundbarDevice, append_unique_id: str): | ||||
|         self.entity_id = f"sensor.{device.device_name}_{append_unique_id}" | ||||
|  |  | |||
|  | @ -3,9 +3,9 @@ import logging | |||
| from homeassistant.components.switch import SwitchEntity | ||||
| from homeassistant.helpers.entity import DeviceInfo | ||||
| 
 | ||||
| from .models import DeviceConfig | ||||
| from .api_extension.SoundbarDevice import SoundbarDevice | ||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN | ||||
| from .models import DeviceConfig | ||||
| 
 | ||||
| _LOGGER = logging.getLogger(__name__) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue