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 | # 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 | ## [0.2.1] Chore: Format repository - 2024-02-08 | ||||||
| 
 | 
 | ||||||
| ### Changed | ### 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, | from homeassistant.components.media_player import (DEVICE_CLASS_SPEAKER, | ||||||
|                                                    MediaPlayerEntity) |                                                    MediaPlayerEntity) | ||||||
| from homeassistant.components.media_player.const import ( | from homeassistant.components.media_player.const import MediaPlayerEntityFeature | ||||||
|     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.helpers.aiohttp_client import async_get_clientsession | from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||||||
| from homeassistant.helpers.entity import DeviceInfo, generate_entity_id | from homeassistant.helpers.entity import DeviceInfo, generate_entity_id | ||||||
| 
 | 
 | ||||||
|  | @ -21,16 +18,16 @@ DEFAULT_NAME = "SmartThings Soundbar" | ||||||
| CONF_MAX_VOLUME = "max_volume" | CONF_MAX_VOLUME = "max_volume" | ||||||
| 
 | 
 | ||||||
| SUPPORT_SMARTTHINGS_SOUNDBAR = ( | SUPPORT_SMARTTHINGS_SOUNDBAR = ( | ||||||
|     SUPPORT_PAUSE |     MediaPlayerEntityFeature.PAUSE | ||||||
|     | SUPPORT_VOLUME_STEP |     | MediaPlayerEntityFeature.VOLUME_STEP | ||||||
|     | SUPPORT_VOLUME_MUTE |     | MediaPlayerEntityFeature.VOLUME_MUTE | ||||||
|     | SUPPORT_VOLUME_SET |     | MediaPlayerEntityFeature.VOLUME_SET | ||||||
|     | SUPPORT_SELECT_SOURCE |     | MediaPlayerEntityFeature.SELECT_SOURCE | ||||||
|     | SUPPORT_TURN_OFF |     | MediaPlayerEntityFeature.TURN_OFF | ||||||
|     | SUPPORT_TURN_ON |     | MediaPlayerEntityFeature.TURN_ON | ||||||
|     | SUPPORT_PLAY |     | MediaPlayerEntityFeature.PLAY | ||||||
|     | SUPPORT_STOP |     | MediaPlayerEntityFeature.STOP | ||||||
|     | SUPPORT_SELECT_SOUND_MODE |     | MediaPlayerEntityFeature.SELECT_SOUND_MODE | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -22,22 +22,13 @@ 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( |             entities.append( | ||||||
|                 EqPresetSelectEntity( |                 EqPresetSelectEntity(device, "eq_preset", "mdi:tune-vertical") | ||||||
|                     device, |  | ||||||
|                     "eq_preset", |  | ||||||
|                 ) |  | ||||||
|             ) |             ) | ||||||
|             entities.append( |             entities.append( | ||||||
|                 SoundModeSelectEntity( |                 SoundModeSelectEntity(device, "sound_mode_preset", "mdi:surround-sound") | ||||||
|                     device, |  | ||||||
|                     "sound_mode_preset", |  | ||||||
|                 ) |  | ||||||
|             ) |             ) | ||||||
|             entities.append( |             entities.append( | ||||||
|                 InputSelectEntity( |                 InputSelectEntity(device, "input_preset", "mdi:video-input-hdmi") | ||||||
|                     device, |  | ||||||
|                     "input_preset", |  | ||||||
|                 ) |  | ||||||
|             ) |             ) | ||||||
|     async_add_entities(entities) |     async_add_entities(entities) | ||||||
|     return True |     return True | ||||||
|  | @ -48,11 +39,13 @@ class EqPresetSelectEntity(SelectEntity): | ||||||
|         self, |         self, | ||||||
|         device: SoundbarDevice, |         device: SoundbarDevice, | ||||||
|         append_unique_id: str, |         append_unique_id: str, | ||||||
|  |         icon_string: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||||
|         self.entity_description = SelectEntityDescription( |         self.entity_description = SelectEntityDescription( | ||||||
|             key=append_unique_id, |             key=append_unique_id, | ||||||
|         ) |         ) | ||||||
|  |         self.__base_icon = icon_string | ||||||
|         self.__device = device |         self.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  | @ -72,6 +65,10 @@ class EqPresetSelectEntity(SelectEntity): | ||||||
|     def name(self): |     def name(self): | ||||||
|         return self.__append_unique_id |         return self.__append_unique_id | ||||||
| 
 | 
 | ||||||
|  |     @property | ||||||
|  |     def icon(self) -> str | None: | ||||||
|  |         return self.__base_icon | ||||||
|  | 
 | ||||||
|     # ------ STATE FUNCTIONS -------- |     # ------ STATE FUNCTIONS -------- | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|  | @ -90,11 +87,13 @@ class SoundModeSelectEntity(SelectEntity): | ||||||
|         self, |         self, | ||||||
|         device: SoundbarDevice, |         device: SoundbarDevice, | ||||||
|         append_unique_id: str, |         append_unique_id: str, | ||||||
|  |         icon_string: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||||
|         self.entity_description = SelectEntityDescription( |         self.entity_description = SelectEntityDescription( | ||||||
|             key=append_unique_id, |             key=append_unique_id, | ||||||
|         ) |         ) | ||||||
|  |         self.__base_icon = icon_string | ||||||
|         self.__device = device |         self.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  | @ -114,6 +113,10 @@ class SoundModeSelectEntity(SelectEntity): | ||||||
|     def name(self): |     def name(self): | ||||||
|         return self.__append_unique_id |         return self.__append_unique_id | ||||||
| 
 | 
 | ||||||
|  |     @property | ||||||
|  |     def icon(self) -> str | None: | ||||||
|  |         return self.__base_icon | ||||||
|  | 
 | ||||||
|     # ------ STATE FUNCTIONS -------- |     # ------ STATE FUNCTIONS -------- | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|  | @ -132,11 +135,13 @@ class InputSelectEntity(SelectEntity): | ||||||
|         self, |         self, | ||||||
|         device: SoundbarDevice, |         device: SoundbarDevice, | ||||||
|         append_unique_id: str, |         append_unique_id: str, | ||||||
|  |         icon_string: str, | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"number.{device.device_name}_{append_unique_id}" |         self.entity_id = f"number.{device.device_name}_{append_unique_id}" | ||||||
|         self.entity_description = SelectEntityDescription( |         self.entity_description = SelectEntityDescription( | ||||||
|             key=append_unique_id, |             key=append_unique_id, | ||||||
|         ) |         ) | ||||||
|  |         self.__base_icon = icon_string | ||||||
|         self.__device = device |         self.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" |         self._attr_unique_id = f"{device.device_id}_sw_{append_unique_id}" | ||||||
|         self._attr_device_info = DeviceInfo( |         self._attr_device_info = DeviceInfo( | ||||||
|  | @ -156,6 +161,10 @@ class InputSelectEntity(SelectEntity): | ||||||
|     def name(self): |     def name(self): | ||||||
|         return self.__append_unique_id |         return self.__append_unique_id | ||||||
| 
 | 
 | ||||||
|  |     @property | ||||||
|  |     def icon(self) -> str | None: | ||||||
|  |         return self.__base_icon | ||||||
|  | 
 | ||||||
|     # ------ STATE FUNCTIONS -------- |     # ------ STATE FUNCTIONS -------- | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|  |  | ||||||
|  | @ -19,16 +19,17 @@ 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", "mdi:volume-high")) | ||||||
|     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, icon_string: str): | ||||||
|         self.entity_id = f"sensor.{device.device_name}_{append_unique_id}" |         self.entity_id = f"sensor.{device.device_name}_{append_unique_id}" | ||||||
|         self.__device = device |         self.__device = device | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{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( |         self._attr_device_info = DeviceInfo( | ||||||
|             identifiers={(DOMAIN, self.__device.device_id)}, |             identifiers={(DOMAIN, self.__device.device_id)}, | ||||||
|             name=self.__device.device_name, |             name=self.__device.device_name, | ||||||
|  | @ -40,6 +41,10 @@ class VolumeSensor(SensorEntity): | ||||||
| 
 | 
 | ||||||
|         _attr_device_class = SensorDeviceClass.VOLUME |         _attr_device_class = SensorDeviceClass.VOLUME | ||||||
| 
 | 
 | ||||||
|  |     @property | ||||||
|  |     def icon(self) -> str | None: | ||||||
|  |         return self.__base_icon | ||||||
|  | 
 | ||||||
|     def update(self) -> None: |     def update(self) -> None: | ||||||
|         """Fetch new state data for the sensor. |         """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, |                     lambda: device.night_mode, | ||||||
|                     device.set_night_mode, |                     device.set_night_mode, | ||||||
|                     device.set_night_mode, |                     device.set_night_mode, | ||||||
|  |                     "mdi:weather-night", | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|             entities.append( |             entities.append( | ||||||
|  | @ -34,6 +35,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|                     lambda: device.bass_mode, |                     lambda: device.bass_mode, | ||||||
|                     device.set_bass_mode, |                     device.set_bass_mode, | ||||||
|                     device.set_bass_mode, |                     device.set_bass_mode, | ||||||
|  |                     "mdi:speaker-wireless", | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|             entities.append( |             entities.append( | ||||||
|  | @ -43,6 +45,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): | ||||||
|                     lambda: device.voice_amplifier, |                     lambda: device.voice_amplifier, | ||||||
|                     device.set_voice_amplifier, |                     device.set_voice_amplifier, | ||||||
|                     device.set_voice_amplifier, |                     device.set_voice_amplifier, | ||||||
|  |                     "mdi:account-voice", | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|     async_add_entities(entities) |     async_add_entities(entities) | ||||||
|  | @ -57,12 +60,14 @@ class SoundbarSwitchAdvancedAudio(SwitchEntity): | ||||||
|         state_function, |         state_function, | ||||||
|         on_function, |         on_function, | ||||||
|         off_function, |         off_function, | ||||||
|  |         icon_string: str = "mdi:toggle-switch-variant", | ||||||
|     ): |     ): | ||||||
|         self.entity_id = f"switch.{device.device_name}_{append_unique_id}" |         self.entity_id = f"switch.{device.device_name}_{append_unique_id}" | ||||||
| 
 | 
 | ||||||
|         self.__device = device |         self.__device = device | ||||||
|         self._name = f"{self.__device.device_name} {append_unique_id}" |         self._name = f"{self.__device.device_name} {append_unique_id}" | ||||||
|         self._attr_unique_id = f"{device.device_id}_sw_{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( |         self._attr_device_info = DeviceInfo( | ||||||
|             identifiers={(DOMAIN, self.__device.device_id)}, |             identifiers={(DOMAIN, self.__device.device_id)}, | ||||||
|             name=self.__device.device_name, |             name=self.__device.device_name, | ||||||
|  | @ -85,6 +90,10 @@ class SoundbarSwitchAdvancedAudio(SwitchEntity): | ||||||
|     def update(self): |     def update(self): | ||||||
|         self.__state = self.__state_function() |         self.__state = self.__state_function() | ||||||
| 
 | 
 | ||||||
|  |     @property | ||||||
|  |     def icon(self) -> str | None: | ||||||
|  |         return self.__base_icon | ||||||
|  | 
 | ||||||
|     # ------ STATE FUNCTIONS -------- |     # ------ STATE FUNCTIONS -------- | ||||||
|     @property |     @property | ||||||
|     def state(self): |     def state(self): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue