Add icons to select, sensor and switches
This commit is contained in:
		
							parent
							
								
									dd61dec79f
								
							
						
					
					
						commit
						d42e1b2832
					
				
							
								
								
									
										11
									
								
								CHANGELOG.md
								
								
								
								
							
							
						
						
									
										11
									
								
								CHANGELOG.md
								
								
								
								
							|  | @ -1,5 +1,16 @@ | |||
| # Changelog | ||||
| 
 | ||||
| ## [0.3.0] Icons and Chore | ||||
| 
 | ||||
| ### Added | ||||
| 
 | ||||
| - Icons for the individual entities | ||||
| 
 | ||||
| ### Changed | ||||
| 
 | ||||
| - Change "magic numbers" to `MediaPlayerEntityFeature` object | ||||
|   For more information see https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation | ||||
| 
 | ||||
| ## [0.2.1] Chore: Format repository - 2024-02-08 | ||||
| 
 | ||||
| ### Changed | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -3,10 +3,7 @@ from typing import Any, Mapping | |||
| 
 | ||||
| from homeassistant.components.media_player import (DEVICE_CLASS_SPEAKER, | ||||
|                                                    MediaPlayerEntity) | ||||
| from homeassistant.components.media_player.const import ( | ||||
|     SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_SELECT_SOUND_MODE, | ||||
|     SUPPORT_SELECT_SOURCE, SUPPORT_STOP, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, | ||||
|     SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_VOLUME_STEP) | ||||
| from homeassistant.components.media_player.const import MediaPlayerEntityFeature | ||||
| from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||
| from homeassistant.helpers.entity import DeviceInfo, generate_entity_id | ||||
| 
 | ||||
|  | @ -21,16 +18,16 @@ DEFAULT_NAME = "SmartThings Soundbar" | |||
| CONF_MAX_VOLUME = "max_volume" | ||||
| 
 | ||||
| SUPPORT_SMARTTHINGS_SOUNDBAR = ( | ||||
|     SUPPORT_PAUSE | ||||
|     | SUPPORT_VOLUME_STEP | ||||
|     | SUPPORT_VOLUME_MUTE | ||||
|     | SUPPORT_VOLUME_SET | ||||
|     | SUPPORT_SELECT_SOURCE | ||||
|     | SUPPORT_TURN_OFF | ||||
|     | SUPPORT_TURN_ON | ||||
|     | SUPPORT_PLAY | ||||
|     | SUPPORT_STOP | ||||
|     | SUPPORT_SELECT_SOUND_MODE | ||||
|     MediaPlayerEntityFeature.PAUSE | ||||
|     | MediaPlayerEntityFeature.VOLUME_STEP | ||||
|     | MediaPlayerEntityFeature.VOLUME_MUTE | ||||
|     | MediaPlayerEntityFeature.VOLUME_SET | ||||
|     | MediaPlayerEntityFeature.SELECT_SOURCE | ||||
|     | MediaPlayerEntityFeature.TURN_OFF | ||||
|     | MediaPlayerEntityFeature.TURN_ON | ||||
|     | MediaPlayerEntityFeature.PLAY | ||||
|     | MediaPlayerEntityFeature.STOP | ||||
|     | MediaPlayerEntityFeature.SELECT_SOUND_MODE | ||||
| ) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -22,22 +22,13 @@ 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( | ||||
|                 EqPresetSelectEntity( | ||||
|                     device, | ||||
|                     "eq_preset", | ||||
|                 ) | ||||
|                 EqPresetSelectEntity(device, "eq_preset", "mdi:tune-vertical") | ||||
|             ) | ||||
|             entities.append( | ||||
|                 SoundModeSelectEntity( | ||||
|                     device, | ||||
|                     "sound_mode_preset", | ||||
|                 ) | ||||
|                 SoundModeSelectEntity(device, "sound_mode_preset", "mdi:surround-sound") | ||||
|             ) | ||||
|             entities.append( | ||||
|                 InputSelectEntity( | ||||
|                     device, | ||||
|                     "input_preset", | ||||
|                 ) | ||||
|                 InputSelectEntity(device, "input_preset", "mdi:video-input-hdmi") | ||||
|             ) | ||||
|     async_add_entities(entities) | ||||
|     return True | ||||
|  | @ -48,11 +39,13 @@ class EqPresetSelectEntity(SelectEntity): | |||
|         self, | ||||
|         device: SoundbarDevice, | ||||
|         append_unique_id: str, | ||||
|         icon_string: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = SelectEntityDescription( | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__base_icon = icon_string | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  | @ -72,6 +65,10 @@ class EqPresetSelectEntity(SelectEntity): | |||
|     def name(self): | ||||
|         return self.__append_unique_id | ||||
| 
 | ||||
|     @property | ||||
|     def icon(self) -> str | None: | ||||
|         return self.__base_icon | ||||
| 
 | ||||
|     # ------ STATE FUNCTIONS -------- | ||||
| 
 | ||||
|     @property | ||||
|  | @ -90,11 +87,13 @@ class SoundModeSelectEntity(SelectEntity): | |||
|         self, | ||||
|         device: SoundbarDevice, | ||||
|         append_unique_id: str, | ||||
|         icon_string: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = SelectEntityDescription( | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__base_icon = icon_string | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  | @ -114,6 +113,10 @@ class SoundModeSelectEntity(SelectEntity): | |||
|     def name(self): | ||||
|         return self.__append_unique_id | ||||
| 
 | ||||
|     @property | ||||
|     def icon(self) -> str | None: | ||||
|         return self.__base_icon | ||||
| 
 | ||||
|     # ------ STATE FUNCTIONS -------- | ||||
| 
 | ||||
|     @property | ||||
|  | @ -132,11 +135,13 @@ class InputSelectEntity(SelectEntity): | |||
|         self, | ||||
|         device: SoundbarDevice, | ||||
|         append_unique_id: str, | ||||
|         icon_string: str, | ||||
|     ): | ||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||
|         self.entity_description = SelectEntityDescription( | ||||
|             key=append_unique_id, | ||||
|         ) | ||||
|         self.__base_icon = icon_string | ||||
|         self.__device = device | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|  | @ -156,6 +161,10 @@ class InputSelectEntity(SelectEntity): | |||
|     def name(self): | ||||
|         return self.__append_unique_id | ||||
| 
 | ||||
|     @property | ||||
|     def icon(self) -> str | None: | ||||
|         return self.__base_icon | ||||
| 
 | ||||
|     # ------ STATE FUNCTIONS -------- | ||||
| 
 | ||||
|     @property | ||||
|  |  | |||
|  | @ -19,16 +19,17 @@ 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", "mdi:volume-high")) | ||||
|     async_add_entities(entities) | ||||
|     return True | ||||
| 
 | ||||
| 
 | ||||
| class VolumeSensor(SensorEntity): | ||||
|     def __init__(self, device: SoundbarDevice, append_unique_id: str): | ||||
|     def __init__(self, device: SoundbarDevice, append_unique_id: str, icon_string: str): | ||||
|         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}" | ||||
|         self.__base_icon = icon_string | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|             identifiers={(DOMAIN, self.__device.device_id)}, | ||||
|             name=self.__device.device_name, | ||||
|  | @ -40,6 +41,10 @@ class VolumeSensor(SensorEntity): | |||
| 
 | ||||
|         _attr_device_class = SensorDeviceClass.VOLUME | ||||
| 
 | ||||
|     @property | ||||
|     def icon(self) -> str | None: | ||||
|         return self.__base_icon | ||||
| 
 | ||||
|     def update(self) -> None: | ||||
|         """Fetch new state data for the sensor. | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | |||
|                     lambda: device.night_mode, | ||||
|                     device.set_night_mode, | ||||
|                     device.set_night_mode, | ||||
|                     "mdi:weather-night", | ||||
|                 ) | ||||
|             ) | ||||
|             entities.append( | ||||
|  | @ -34,6 +35,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | |||
|                     lambda: device.bass_mode, | ||||
|                     device.set_bass_mode, | ||||
|                     device.set_bass_mode, | ||||
|                     "mdi:speaker-wireless", | ||||
|                 ) | ||||
|             ) | ||||
|             entities.append( | ||||
|  | @ -43,6 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | |||
|                     lambda: device.voice_amplifier, | ||||
|                     device.set_voice_amplifier, | ||||
|                     device.set_voice_amplifier, | ||||
|                     "mdi:account-voice", | ||||
|                 ) | ||||
|             ) | ||||
|     async_add_entities(entities) | ||||
|  | @ -57,12 +60,14 @@ class SoundbarSwitchAdvancedAudio(SwitchEntity): | |||
|         state_function, | ||||
|         on_function, | ||||
|         off_function, | ||||
|         icon_string: str = "mdi:toggle-switch-variant", | ||||
|     ): | ||||
|         self.entity_id = f"switch.{device.device_name}_{append_unique_id}" | ||||
| 
 | ||||
|         self.__device = device | ||||
|         self._name = f"{self.__device.device_name} {append_unique_id}" | ||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||
|         self.__base_icon = icon_string | ||||
|         self._attr_device_info = DeviceInfo( | ||||
|             identifiers={(DOMAIN, self.__device.device_id)}, | ||||
|             name=self.__device.device_name, | ||||
|  | @ -85,6 +90,10 @@ class SoundbarSwitchAdvancedAudio(SwitchEntity): | |||
|     def update(self): | ||||
|         self.__state = self.__state_function() | ||||
| 
 | ||||
|     @property | ||||
|     def icon(self) -> str | None: | ||||
|         return self.__base_icon | ||||
| 
 | ||||
|     # ------ STATE FUNCTIONS -------- | ||||
|     @property | ||||
|     def state(self): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue