Handle UPS disconnects in NUT (#35758)
This commit is contained in:
parent
affd11b372
commit
50105eed74
2 changed files with 6 additions and 2 deletions
|
@ -18,7 +18,7 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
COORDINATOR,
|
COORDINATOR,
|
||||||
|
@ -61,7 +61,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
async def async_update_data():
|
async def async_update_data():
|
||||||
"""Fetch data from NUT."""
|
"""Fetch data from NUT."""
|
||||||
async with async_timeout.timeout(10):
|
async with async_timeout.timeout(10):
|
||||||
return await hass.async_add_executor_job(data.update)
|
await hass.async_add_executor_job(data.update)
|
||||||
|
if not data.status:
|
||||||
|
raise UpdateFailed("Error fetching UPS state")
|
||||||
|
|
||||||
coordinator = DataUpdateCoordinator(
|
coordinator = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -189,6 +189,8 @@ class NUTSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return entity state from ups."""
|
"""Return entity state from ups."""
|
||||||
|
if not self._data.status:
|
||||||
|
return None
|
||||||
if self._type == KEY_STATUS_DISPLAY:
|
if self._type == KEY_STATUS_DISPLAY:
|
||||||
return _format_display_state(self._data.status)
|
return _format_display_state(self._data.status)
|
||||||
return self._data.status.get(self._type)
|
return self._data.status.get(self._type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue