Cleanup and optimization for Zerproc (#44430)
* Cleanup and optimization for Zerproc * Remove unnecessary extra method * Add debug log for exceptions on disconnect
This commit is contained in:
parent
bf253819dd
commit
f89c682ea6
5 changed files with 22 additions and 11 deletions
|
@ -110,17 +110,18 @@ class ZerprocLight(LightEntity):
|
||||||
"""Run when entity about to be added to hass."""
|
"""Run when entity about to be added to hass."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
self.hass.bus.async_listen_once(
|
self.hass.bus.async_listen_once(
|
||||||
EVENT_HOMEASSISTANT_STOP, self.on_hass_shutdown
|
EVENT_HOMEASSISTANT_STOP, self.async_will_remove_from_hass
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self, *args) -> None:
|
||||||
"""Run when entity will be removed from hass."""
|
"""Run when entity will be removed from hass."""
|
||||||
|
try:
|
||||||
await self._light.disconnect()
|
await self._light.disconnect()
|
||||||
|
except pyzerproc.ZerprocException:
|
||||||
async def on_hass_shutdown(self, event):
|
_LOGGER.debug(
|
||||||
"""Execute when Home Assistant is shutting down."""
|
"Exception disconnected from %s", self.entity_id, exc_info=True
|
||||||
await self._light.disconnect()
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -192,7 +193,7 @@ class ZerprocLight(LightEntity):
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch new state data for this light."""
|
||||||
try:
|
try:
|
||||||
if not await self._light.is_connected():
|
if not self._available:
|
||||||
await self._light.connect()
|
await self._light.connect()
|
||||||
state = await self._light.get_state()
|
state = await self._light.get_state()
|
||||||
except pyzerproc.ZerprocException:
|
except pyzerproc.ZerprocException:
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/zerproc",
|
"documentation": "https://www.home-assistant.io/integrations/zerproc",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyzerproc==0.4.3"
|
"pyzerproc==0.4.7"
|
||||||
],
|
],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@emlove"
|
"@emlove"
|
||||||
|
|
|
@ -1904,7 +1904,7 @@ pyxeoma==1.4.1
|
||||||
pyzbar==0.1.7
|
pyzbar==0.1.7
|
||||||
|
|
||||||
# homeassistant.components.zerproc
|
# homeassistant.components.zerproc
|
||||||
pyzerproc==0.4.3
|
pyzerproc==0.4.7
|
||||||
|
|
||||||
# homeassistant.components.qnap
|
# homeassistant.components.qnap
|
||||||
qnapstats==0.3.0
|
qnapstats==0.3.0
|
||||||
|
|
|
@ -939,7 +939,7 @@ pywemo==0.5.3
|
||||||
pywilight==0.0.65
|
pywilight==0.0.65
|
||||||
|
|
||||||
# homeassistant.components.zerproc
|
# homeassistant.components.zerproc
|
||||||
pyzerproc==0.4.3
|
pyzerproc==0.4.7
|
||||||
|
|
||||||
# homeassistant.components.rachio
|
# homeassistant.components.rachio
|
||||||
rachiopy==1.0.3
|
rachiopy==1.0.3
|
||||||
|
|
|
@ -173,6 +173,16 @@ async def test_remove_entry(hass, mock_light, mock_entry):
|
||||||
assert mock_disconnect.called
|
assert mock_disconnect.called
|
||||||
|
|
||||||
|
|
||||||
|
async def test_remove_entry_exceptions_caught(hass, mock_light, mock_entry):
|
||||||
|
"""Assert that disconnect exceptions are caught."""
|
||||||
|
with patch.object(
|
||||||
|
mock_light, "disconnect", side_effect=pyzerproc.ZerprocException("Mock error")
|
||||||
|
) as mock_disconnect:
|
||||||
|
await hass.config_entries.async_remove(mock_entry.entry_id)
|
||||||
|
|
||||||
|
assert mock_disconnect.called
|
||||||
|
|
||||||
|
|
||||||
async def test_light_turn_on(hass, mock_light):
|
async def test_light_turn_on(hass, mock_light):
|
||||||
"""Test ZerprocLight turn_on."""
|
"""Test ZerprocLight turn_on."""
|
||||||
utcnow = dt_util.utcnow()
|
utcnow = dt_util.utcnow()
|
||||||
|
|
Loading…
Add table
Reference in a new issue