Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions homeassistant/components/rituals_perfume_genie/switch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""Support for Rituals Perfume Genie switches."""
import asyncio
from datetime import timedelta
import logging

import aiohttp

from homeassistant.components.switch import SwitchEntity

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(seconds=30)

ON_STATE = "1"
Expand Down Expand Up @@ -33,6 +39,7 @@ class DiffuserSwitch(SwitchEntity):
def __init__(self, diffuser):
"""Initialize the switch."""
self._diffuser = diffuser
self._available = True

@property
def device_info(self):
Expand All @@ -53,7 +60,7 @@ def unique_id(self):
@property
def available(self):
"""Return if the device is available."""
return self._diffuser.data["hub"]["status"] == AVAILABLE_STATE
return self._available

@property
def name(self):
Expand Down Expand Up @@ -89,4 +96,9 @@ async def async_turn_off(self, **kwargs):

async def async_update(self):
"""Update the data of the device."""
await self._diffuser.update_data()
try:
await self._diffuser.update_data()
self._available = self._diffuser.data["hub"]["status"] == AVAILABLE_STATE
Comment thread
milanmeu marked this conversation as resolved.
Outdated
except (asyncio.TimeoutError, aiohttp.ClientError):
Comment thread
milanmeu marked this conversation as resolved.
Outdated
self._available = False
_LOGGER.error("Unable to retrieve data from rituals.sense-company.com")