🎨 Chore: format files with `black` and `isort`
The title says it all, still for more information take a look at the merge-request #15. --------- Co-authored-by: samuelspagl <samuel@spagl-media.de>
This commit is contained in:
parent
30ef090d9e
commit
dd61dec79f
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# 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
|
## [0.2.0] Add volume sensor - 2024-02-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -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,7 +37,8 @@ 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_max_value=6,
|
||||||
native_min_value=-10,
|
native_min_value=-10,
|
||||||
mode=NumberMode.BOX,
|
mode=NumberMode.BOX,
|
||||||
native_step=1,
|
native_step=1,
|
||||||
|
|
|
@ -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__)
|
||||||
|
|
||||||
|
@ -47,7 +50,8 @@ class EqPresetSelectEntity(SelectEntity):
|
||||||
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}"
|
||||||
|
@ -88,7 +92,8 @@ class SoundModeSelectEntity(SelectEntity):
|
||||||
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}"
|
||||||
|
@ -129,7 +134,8 @@ class InputSelectEntity(SelectEntity):
|
||||||
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}"
|
||||||
|
|
|
@ -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