Skip to content

Commit

Permalink
fix: add availability state to switches
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Sep 21, 2019
1 parent 1a53b98 commit fd44b7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions custom_components/alexa_media/media_player.py
Expand Up @@ -371,11 +371,15 @@ async def refresh(self, device=None):
if self._session['transport'] is not None:
self._shuffle = (self._session['transport']
['shuffle'] == "SELECTED"
if ('shuffle' in self._session['transport'])
if ('shuffle' in self._session['transport']
and self._session['transport']['shuffle']
!= 'DISABLED')
else None)
self._repeat = (self._session['transport']
['repeat'] == "SELECTED"
if ('repeat' in self._session['transport'])
if ('repeat' in self._session['transport']
and self._session['transport']['repeat']
!= 'DISABLED')
else None)

@property
Expand Down
7 changes: 6 additions & 1 deletion custom_components/alexa_media/switch.py
Expand Up @@ -193,7 +193,7 @@ async def _set_switch(self, state, **kwargs):
@property
def is_on(self):
"""Return true if on."""
return getattr(self._client, self._switch_property)
return self.available and getattr(self._client, self._switch_property)

async def async_turn_on(self, **kwargs):
"""Turn on switch."""
Expand All @@ -203,6 +203,11 @@ async def async_turn_off(self, **kwargs):
"""Turn off switch."""
await self._set_switch(False, **kwargs)

@property
def available(self):
"""Return the availabilty of the switch."""
return getattr(self._client, self._switch_property) is not None

@property
def unique_id(self):
"""Return the unique ID."""
Expand Down

0 comments on commit fd44b7c

Please sign in to comment.