Fix lg_soundbar callback (#38259)

* Don't schedule an update if the hass instance isn't instantiated

If we get a status update packet before self.hass exists, we trip a
"assert self.hass is not None" that was added in 0.112 and setup fails.

* Fix callback hander properly

The right fix is to register the callback after hass is ready for it.

* Remove unnecessary check

This is now guaranteed by the core code.

* Don't request an immediate device update and do an async connect.

* Remove unnecessary return
This commit is contained in:
Matthew Garrett 2020-07-28 00:55:24 -07:00 committed by GitHub
parent ae8a38757a
commit 508fc3fa0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@ SUPPORT_LG = (
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the LG platform."""
if discovery_info is not None:
add_entities([LGDevice(discovery_info)], True)
add_entities([LGDevice(discovery_info)])
class LGDevice(MediaPlayerEntity):
@ -33,8 +33,8 @@ class LGDevice(MediaPlayerEntity):
def __init__(self, discovery_info):
"""Initialize the LG speakers."""
host = discovery_info.get("host")
port = discovery_info.get("port")
self._host = discovery_info.get("host")
self._port = discovery_info.get("port")
self._name = ""
self._volume = 0
@ -53,8 +53,17 @@ class LGDevice(MediaPlayerEntity):
self._woofer_volume_max = 0
self._bass = 0
self._treble = 0
self._device = None
self._device = temescal.temescal(host, port=port, callback=self.handle_event)
async def async_added_to_hass(self):
"""Register the callback after hass is ready for it."""
await self.hass.async_add_executor_job(self._connect)
def _connect(self):
"""Perform the actual devices setup."""
self._device = temescal.temescal(
self._host, port=self._port, callback=self.handle_event
)
self.update()
def handle_event(self, response):