Merge branch 'feature/add-volume-sensor' of https://github.com/samuelspagl/ha_samsung_soundbar into feature/add-volume-sensor
This commit is contained in:
		
						commit
						c61b2ba3f2
					
				|  | @ -1,16 +1,14 @@ | ||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
| from homeassistant.components.sensor import (SensorDeviceClass, SensorEntity, | from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass | ||||||
|                                              SensorStateClass) |  | ||||||
| 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 | from homeassistant.helpers.entity import DeviceInfo | ||||||
| 
 | 
 | ||||||
| _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 = [] | ||||||
|  | @ -19,11 +17,14 @@ 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(VolumeSensor(device, "volume_level")) |             entities.append( | ||||||
|  |                 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}" | ||||||
|  | @ -45,4 +46,4 @@ class VolumeSensor(SensorEntity): | ||||||
| 
 | 
 | ||||||
|         This is the only method that should fetch new data for Home Assistant. |         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 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue