mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 23:37:18 +00:00
Catch expected errors and log them in rituals perfume genie (#48870)
* Add update error logging * Move try available to else * Remove TimeoutError
This commit is contained in:
parent
a59460a233
commit
bdbc38c937
@ -1,10 +1,15 @@
|
|||||||
"""Support for Rituals Perfume Genie switches."""
|
"""Support for Rituals Perfume Genie switches."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
ON_STATE = "1"
|
ON_STATE = "1"
|
||||||
@ -33,6 +38,7 @@ class DiffuserSwitch(SwitchEntity):
|
|||||||
def __init__(self, diffuser):
|
def __init__(self, diffuser):
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
self._diffuser = diffuser
|
self._diffuser = diffuser
|
||||||
|
self._available = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
@ -53,7 +59,7 @@ class DiffuserSwitch(SwitchEntity):
|
|||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return if the device is available."""
|
"""Return if the device is available."""
|
||||||
return self._diffuser.data["hub"]["status"] == AVAILABLE_STATE
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -89,4 +95,10 @@ class DiffuserSwitch(SwitchEntity):
|
|||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update the data of the device."""
|
"""Update the data of the device."""
|
||||||
|
try:
|
||||||
await self._diffuser.update_data()
|
await self._diffuser.update_data()
|
||||||
|
except aiohttp.ClientError:
|
||||||
|
self._available = False
|
||||||
|
_LOGGER.error("Unable to retrieve data from rituals.sense-company.com")
|
||||||
|
else:
|
||||||
|
self._available = self._diffuser.data["hub"]["status"] == AVAILABLE_STATE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user