diff --git a/custom_components/samsung_soundbar/sensor.py b/custom_components/samsung_soundbar/sensor.py index 68fea44..6712b85 100644 --- a/custom_components/samsung_soundbar/sensor.py +++ b/custom_components/samsung_soundbar/sensor.py @@ -1,16 +1,14 @@ import logging -from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity, - SensorStateClass) -from homeassistant.helpers.entity import DeviceInfo +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 .models import DeviceConfig +from homeassistant.helpers.entity import DeviceInfo _LOGGER = logging.getLogger(__name__) - async def async_setup_entry(hass, config_entry, async_add_entities): domain_data = hass.data[DOMAIN] entities = [] @@ -19,11 +17,14 @@ 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}" @@ -45,4 +46,4 @@ class VolumeSensor(SensorEntity): This is the only method that should fetch new data for Home Assistant. """ - self._attr_native_value = self.__device.volume_level * 100 + self._attr_native_value = self.__device.device.status.volume