2024-02-08 18:45:32 +03:00
|
|
|
import logging
|
|
|
|
|
Feature: Add more fine grained configuration steps (#28)
> ⚠️ Please read the following carefully:
> This release is a bit special. As "something" on Samsung's side changed,
> it is currently not possible to retrieve the status of "custom capabilities", eg.
> woofer, soundmode, eq, and others. Therefore I decided to give the option to
> disable the entities of these features as the value of these entities is not trustworthy.
> Instead I implemented all of these and more (thanks to @whitebearded) as service calls.
> Have fun using them!
### Added
- Configuration flow options for enable / disable
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "eq" feature
- added `media_player` support for next and previous track
- Service calls for:
- "advanced audio" features (NightMode, Bassmode, VoiceEnhancer)
- "woofer" feature
- "soundmode" feature
- "speaker_level"
- "rear_speaker_mode"
- "space_fit_sound"
- "active_voice_amplifier"
### Changed
- Fixed state, also displaying "playing" and "paused" values
---------
Co-authored-by: Samuel Spagl <samuel.spagl@kobil.com>
2024-06-09 18:13:38 +03:00
|
|
|
from homeassistant.components.sensor import (
|
|
|
|
SensorDeviceClass,
|
|
|
|
SensorEntity,
|
|
|
|
SensorStateClass,
|
|
|
|
)
|
2024-02-08 18:58:57 +03:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2024-02-08 18:45:32 +03:00
|
|
|
|
|
|
|
from .api_extension.SoundbarDevice import SoundbarDevice
|
|
|
|
from .const import CONF_ENTRY_DEVICE_ID, DOMAIN
|
2024-02-08 18:58:57 +03:00
|
|
|
from .models import DeviceConfig
|
2024-02-08 18:45:32 +03:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2024-02-08 18:58:57 +03:00
|
|
|
|
2024-02-08 18:45:32 +03:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
domain_data = hass.data[DOMAIN]
|
|
|
|
entities = []
|
|
|
|
for key in domain_data.devices:
|
|
|
|
device_config: DeviceConfig = domain_data.devices[key]
|
|
|
|
device = device_config.device
|
|
|
|
|
|
|
|
if device.device_id == config_entry.data.get(CONF_ENTRY_DEVICE_ID):
|
2024-03-12 16:39:12 +03:00
|
|
|
entities.append(VolumeSensor(device, "volume_level", "mdi:volume-high"))
|
2024-02-08 18:45:32 +03:00
|
|
|
async_add_entities(entities)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class VolumeSensor(SensorEntity):
|
2024-03-12 16:39:12 +03:00
|
|
|
def __init__(self, device: SoundbarDevice, append_unique_id: str, icon_string: str):
|
2024-02-08 18:45:32 +03:00
|
|
|
self.entity_id = f"sensor.{device.device_name}_{append_unique_id}"
|
|
|
|
self.__device = device
|
|
|
|
self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}"
|
2024-03-12 16:39:12 +03:00
|
|
|
self.__base_icon = icon_string
|
2024-02-08 18:45:32 +03:00
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, self.__device.device_id)},
|
|
|
|
name=self.__device.device_name,
|
|
|
|
manufacturer=self.__device.manufacturer,
|
|
|
|
model=self.__device.model,
|
|
|
|
sw_version=self.__device.firmware_version,
|
|
|
|
)
|
|
|
|
self.__append_unique_id = append_unique_id
|
|
|
|
|
|
|
|
_attr_device_class = SensorDeviceClass.VOLUME
|
|
|
|
|
2024-03-12 16:39:12 +03:00
|
|
|
@property
|
|
|
|
def icon(self) -> str | None:
|
|
|
|
return self.__base_icon
|
|
|
|
|
2024-02-08 18:45:32 +03:00
|
|
|
def update(self) -> None:
|
|
|
|
"""Fetch new state data for the sensor.
|
|
|
|
|
|
|
|
This is the only method that should fetch new data for Home Assistant.
|
|
|
|
"""
|
|
|
|
self._attr_native_value = self.__device.device.status.volume
|