From b5794f3c1b479520e94316aa131b097a480a8754 Mon Sep 17 00:00:00 2001 From: Samuel Spagl <46893256+samuelspagl@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:18:34 +0100 Subject: [PATCH] Fix scaling on sensor Previously the sensor was displaying the scaled amount applied to the slider / number (between 0 and 1). Now it is displaying the raw value. --- custom_components/samsung_soundbar/sensor.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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