format project with black and isort

This commit is contained in:
samuelspagl 2024-02-08 16:54:08 +01:00
parent 30ef090d9e
commit dd04d8f0d4
8 changed files with 79 additions and 77 deletions

View File

@ -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"]

View File

@ -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__)

View File

@ -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__)

View File

@ -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__)

View File

@ -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,7 +37,8 @@ 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,
self.entity_description = NumberEntityDescription(
native_max_value=6,
native_min_value=-10,
mode=NumberMode.BOX,
native_step=1,

View File

@ -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__)
@ -47,7 +50,8 @@ class EqPresetSelectEntity(SelectEntity):
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}"
@ -88,7 +92,8 @@ class SoundModeSelectEntity(SelectEntity):
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}"
@ -129,7 +134,8 @@ class InputSelectEntity(SelectEntity):
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}"

View File

@ -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}"

View File

@ -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__)