1 """Support for LG soundbars."""
3 from __future__
import annotations
11 MediaPlayerEntityFeature,
20 from .const
import DOMAIN
25 config_entry: ConfigEntry,
26 async_add_entities: AddEntitiesCallback,
28 """Set up media_player from a config entry created in the integrations UI."""
32 config_entry.data[CONF_HOST],
33 config_entry.data[CONF_PORT],
34 config_entry.unique_id
or config_entry.entry_id,
41 """Representation of an LG soundbar device."""
43 _attr_should_poll =
False
44 _attr_state = MediaPlayerState.ON
45 _attr_supported_features = (
46 MediaPlayerEntityFeature.VOLUME_SET
47 | MediaPlayerEntityFeature.VOLUME_MUTE
48 | MediaPlayerEntityFeature.TURN_ON
49 | MediaPlayerEntityFeature.TURN_OFF
50 | MediaPlayerEntityFeature.SELECT_SOURCE
51 | MediaPlayerEntityFeature.SELECT_SOUND_MODE
53 _attr_has_entity_name =
True
57 """Initialize the LG speakers."""
80 identifiers={(DOMAIN, unique_id)}, name=host
84 """Register the callback after hass is ready for it."""
85 await self.
hasshass.async_add_executor_job(self.
_connect_connect)
88 """Perform the actual devices setup."""
89 self.
_device_device = temescal.temescal(
92 self.
_device_device.get_product_info()
93 self.
_device_device.get_mac_info()
97 """Handle responses from the speakers."""
98 data = response.get(
"data")
or {}
99 if response[
"msg"] ==
"EQ_VIEW_INFO":
101 elif response[
"msg"] ==
"SPK_LIST_VIEW_INFO":
103 self.
_volume_volume = data[
"i_vol"]
104 if "i_vol_min" in data:
106 if "i_vol_max" in data:
109 self.
_mute_mute = data[
"b_mute"]
110 if "i_curr_func" in data:
111 self.
_function_function = data[
"i_curr_func"]
112 if "b_powerstatus" in data:
113 if data[
"b_powerstatus"]:
117 elif response[
"msg"] ==
"FUNC_VIEW_INFO":
118 if "i_curr_func" in data:
119 self.
_function_function = data[
"i_curr_func"]
120 if "ai_func_list" in data:
121 self.
_functions_functions = data[
"ai_func_list"]
122 elif response[
"msg"] ==
"SETTING_VIEW_INFO":
123 if "i_rear_min" in data:
125 if "i_rear_max" in data:
127 if "i_rear_level" in data:
129 if "i_woofer_min" in data:
131 if "i_woofer_max" in data:
133 if "i_woofer_level" in data:
135 if "i_curr_eq" in data:
137 if "s_user_name" in data:
138 self.
_attr_name_attr_name = data[
"s_user_name"]
143 """Update the equalisers."""
145 self.
_bass_bass = data[
"i_bass"]
146 if "i_treble" in data:
147 self.
_treble_treble = data[
"i_treble"]
148 if "ai_eq_list" in data:
150 if "i_curr_eq" in data:
154 """Trigger updates from the device."""
158 self.
_device_device.get_settings()
162 """Volume level of the media player (0..1)."""
169 """Boolean if volume is currently muted."""
170 return self.
_mute_mute
174 """Return the current sound mode."""
177 return temescal.equalisers[self.
_equaliser_equaliser]
181 """Return the available sound modes."""
183 temescal.equalisers[equaliser]
185 if equaliser < len(temescal.equalisers)
190 """Return the current input source."""
191 if self.
_function_function == -1
or self.
_function_function >= len(temescal.functions):
193 return temescal.functions[self.
_function_function]
197 """List of available input sources."""
199 temescal.functions[function]
201 if function < len(temescal.functions)
205 """Set volume level, range 0..1."""
210 """Mute (true) or unmute (false) media player."""
211 self.
_device_device.set_mute(mute)
214 """Select input source."""
215 self.
_device_device.set_func(temescal.functions.index(source))
218 """Set Sound Mode for Receiver.."""
219 self.
_device_device.set_eq(temescal.equalisers.index(sound_mode))
222 """Turn the media player on."""
226 """Turn the media player off."""
230 """Set the media player state."""
231 self.
_device_device.send_packet(
232 {
"cmd":
"set",
"data": {
"b_powerkey": status},
"msg":
"SPK_LIST_VIEW_INFO"}
None schedule_update_ha_state(self, bool force_refresh=False)
dict[str, Any]|None get_info(HomeAssistant hass)