format project with black and isort
This commit is contained in:
		
							parent
							
								
									30ef090d9e
								
							
						
					
					
						commit
						dd04d8f0d4
					
				|  | @ -1,14 +1,17 @@ | ||||||
| import asyncio | import asyncio | ||||||
| import datetime | import datetime | ||||||
| import json | import json | ||||||
|  | import logging | ||||||
| import time | import time | ||||||
| from urllib.parse import quote | from urllib.parse import quote | ||||||
| import logging | 
 | ||||||
| from pysmartthings import DeviceEntity | from pysmartthings import DeviceEntity | ||||||
| 
 | 
 | ||||||
| from ..const import DOMAIN | from ..const import DOMAIN | ||||||
|  | 
 | ||||||
| log = logging.getLogger(__name__) | 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 | ||||||
|  | @ -70,12 +73,17 @@ class SoundbarDevice: | ||||||
|         await asyncio.sleep(0.1) |         await asyncio.sleep(0.1) | ||||||
|         payload = await self.get_execute_status() |         payload = await self.get_execute_status() | ||||||
|         retry = 0 |         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) |             await asyncio.sleep(0.2) | ||||||
|             payload = await self.get_execute_status() |             payload = await self.get_execute_status() | ||||||
|             retry += 1 |             retry += 1 | ||||||
|         if retry == 10: |         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 |             return | ||||||
| 
 | 
 | ||||||
|         self.__supported_soundmodes = payload[ |         self.__supported_soundmodes = payload[ | ||||||
|  | @ -88,12 +96,14 @@ class SoundbarDevice: | ||||||
|         await asyncio.sleep(0.1) |         await asyncio.sleep(0.1) | ||||||
|         payload = await self.get_execute_status() |         payload = await self.get_execute_status() | ||||||
|         retry = 0 |         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) |             await asyncio.sleep(0.2) | ||||||
|             payload = await self.get_execute_status() |             payload = await self.get_execute_status() | ||||||
|             retry += 1 |             retry += 1 | ||||||
|         if retry == 10: |         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 |             return | ||||||
|         self.__woofer_level = payload["x.com.samsung.networkaudio.woofer"] |         self.__woofer_level = payload["x.com.samsung.networkaudio.woofer"] | ||||||
|         self.__woofer_connection = payload["x.com.samsung.networkaudio.connection"] |         self.__woofer_connection = payload["x.com.samsung.networkaudio.connection"] | ||||||
|  | @ -103,12 +113,14 @@ class SoundbarDevice: | ||||||
|         await asyncio.sleep(0.1) |         await asyncio.sleep(0.1) | ||||||
|         payload = await self.get_execute_status() |         payload = await self.get_execute_status() | ||||||
|         retry = 0 |         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) |             await asyncio.sleep(0.2) | ||||||
|             payload = await self.get_execute_status() |             payload = await self.get_execute_status() | ||||||
|             retry += 1 |             retry += 1 | ||||||
|         if retry == 10: |         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 |             return | ||||||
|         self.__active_eq_preset = payload["x.com.samsung.networkaudio.EQname"] |         self.__active_eq_preset = payload["x.com.samsung.networkaudio.EQname"] | ||||||
|         self.__supported_eq_presets = payload[ |         self.__supported_eq_presets = payload[ | ||||||
|  | @ -123,12 +135,14 @@ class SoundbarDevice: | ||||||
| 
 | 
 | ||||||
|         payload = await self.get_execute_status() |         payload = await self.get_execute_status() | ||||||
|         retry = 0 |         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) |             await asyncio.sleep(0.2) | ||||||
|             payload = await self.get_execute_status() |             payload = await self.get_execute_status() | ||||||
|             retry += 1 |             retry += 1 | ||||||
|         if retry == 10: |         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 |             return | ||||||
| 
 | 
 | ||||||
|         self.__night_mode = payload["x.com.samsung.networkaudio.nightmode"] |         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 homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||||
| from pysmartthings import APIResponseError | from pysmartthings import APIResponseError | ||||||
| 
 | 
 | ||||||
| from .const import ( | from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | ||||||
|     CONF_ENTRY_API_KEY, |                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) | ||||||
|     CONF_ENTRY_DEVICE_ID, |  | ||||||
|     CONF_ENTRY_DEVICE_NAME, |  | ||||||
|     CONF_ENTRY_MAX_VOLUME, |  | ||||||
|     DOMAIN, |  | ||||||
| ) |  | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,9 +6,9 @@ from homeassistant.core import HomeAssistant | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| from homeassistant.helpers.typing import UndefinedType | from homeassistant.helpers.typing import UndefinedType | ||||||
| 
 | 
 | ||||||
| from .models import DeviceConfig |  | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice | 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__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,33 +1,18 @@ | ||||||
| import logging | import logging | ||||||
| from typing import Any, Mapping | from typing import Any, Mapping | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.media_player import ( | from homeassistant.components.media_player import (DEVICE_CLASS_SPEAKER, | ||||||
|     DEVICE_CLASS_SPEAKER, |                                                    MediaPlayerEntity) | ||||||
|     MediaPlayerEntity, |  | ||||||
| ) |  | ||||||
| from homeassistant.components.media_player.const import ( | from homeassistant.components.media_player.const import ( | ||||||
|     SUPPORT_PAUSE, |     SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_SELECT_SOUND_MODE, | ||||||
|     SUPPORT_PLAY, |     SUPPORT_SELECT_SOURCE, SUPPORT_STOP, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, | ||||||
|     SUPPORT_SELECT_SOUND_MODE, |     SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_VOLUME_STEP) | ||||||
|     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.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 ( | from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, | ||||||
|     CONF_ENTRY_API_KEY, |                     CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) | ||||||
|     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,11 +1,13 @@ | ||||||
| import logging | 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 homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .models import DeviceConfig |  | ||||||
| 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, DOMAIN | ||||||
|  | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  | @ -35,13 +37,14 @@ class SoundbarWooferNumberEntity(NumberEntity): | ||||||
|         append_unique_id: str, |         append_unique_id: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||||
|         self.entity_description = NumberEntityDescription(native_max_value=6, |         self.entity_description = NumberEntityDescription( | ||||||
|                                                           native_min_value=-10, |             native_max_value=6, | ||||||
|                                                           mode=NumberMode.BOX, |             native_min_value=-10, | ||||||
|                                                           native_step=1, |             mode=NumberMode.BOX, | ||||||
|                                                           native_unit_of_measurement="dB", |             native_step=1, | ||||||
|                                                           key=append_unique_id, |             native_unit_of_measurement="dB", | ||||||
|                                                           ) |             key=append_unique_id, | ||||||
|  |         ) | ||||||
|         self.__device = device |         self.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  |  | ||||||
|  | @ -1,12 +1,15 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.number import NumberEntity, NumberEntityDescription, NumberMode | from homeassistant.components.number import (NumberEntity, | ||||||
| from homeassistant.components.select import SelectEntityDescription, SelectEntity |                                              NumberEntityDescription, | ||||||
|  |                                              NumberMode) | ||||||
|  | from homeassistant.components.select import (SelectEntity, | ||||||
|  |                                              SelectEntityDescription) | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .models import DeviceConfig |  | ||||||
| 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, DOMAIN | ||||||
|  | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  | @ -42,13 +45,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
| 
 | 
 | ||||||
| class EqPresetSelectEntity(SelectEntity): | class EqPresetSelectEntity(SelectEntity): | ||||||
|     def __init__( |     def __init__( | ||||||
|             self, |         self, | ||||||
|             device: SoundbarDevice, |         device: SoundbarDevice, | ||||||
|             append_unique_id: str, |         append_unique_id: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         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.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  | @ -83,13 +87,14 @@ class EqPresetSelectEntity(SelectEntity): | ||||||
| 
 | 
 | ||||||
| class SoundModeSelectEntity(SelectEntity): | class SoundModeSelectEntity(SelectEntity): | ||||||
|     def __init__( |     def __init__( | ||||||
|             self, |         self, | ||||||
|             device: SoundbarDevice, |         device: SoundbarDevice, | ||||||
|             append_unique_id: str, |         append_unique_id: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         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.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  | @ -124,13 +129,14 @@ class SoundModeSelectEntity(SelectEntity): | ||||||
| 
 | 
 | ||||||
| class InputSelectEntity(SelectEntity): | class InputSelectEntity(SelectEntity): | ||||||
|     def __init__( |     def __init__( | ||||||
|             self, |         self, | ||||||
|             device: SoundbarDevice, |         device: SoundbarDevice, | ||||||
|             append_unique_id: str, |         append_unique_id: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         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.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  |  | ||||||
|  | @ -1,14 +1,16 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass | from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity, | ||||||
| 
 |                                              SensorStateClass) | ||||||
| from .models import DeviceConfig |  | ||||||
| from .api_extension.SoundbarDevice import SoundbarDevice |  | ||||||
| from .const import CONF_ENTRY_DEVICE_ID, DOMAIN |  | ||||||
| from homeassistant.helpers.entity import DeviceInfo | 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__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| async def async_setup_entry(hass, config_entry, async_add_entities): | async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|     domain_data = hass.data[DOMAIN] |     domain_data = hass.data[DOMAIN] | ||||||
|     entities = [] |     entities = [] | ||||||
|  | @ -17,14 +19,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|         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): | ||||||
|             entities.append( |             entities.append(VolumeSensor(device, "volume_level")) | ||||||
|                 VolumeSensor(device, "volume_level") |  | ||||||
|             ) |  | ||||||
|     async_add_entities(entities) |     async_add_entities(entities) | ||||||
|     return True |     return True | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| class VolumeSensor(SensorEntity): | class VolumeSensor(SensorEntity): | ||||||
|     def __init__(self, device: SoundbarDevice, append_unique_id: str): |     def __init__(self, device: SoundbarDevice, append_unique_id: str): | ||||||
|         self.entity_id = f"sensor.{device.device_name}_{append_unique_id}" |         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.components.switch import SwitchEntity | ||||||
| from homeassistant.helpers.entity import DeviceInfo | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| from .models import DeviceConfig |  | ||||||
| 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, DOMAIN | ||||||
|  | from .models import DeviceConfig | ||||||
| 
 | 
 | ||||||
| _LOGGER = logging.getLogger(__name__) | _LOGGER = logging.getLogger(__name__) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue