Skip to content

Commit

Permalink
Changed: Support offline slides
Browse files Browse the repository at this point in the history
  • Loading branch information
ualex73 committed Jul 9, 2019
1 parent 52f74b2 commit 202f413
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
51 changes: 36 additions & 15 deletions goslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,44 @@ async def update_slides(now):
hass.data[DOMAIN][SLIDES][key]['pos'] = None

for slide in result:
if 'device_id' in slide:
uid = slide['device_id'].replace('slide_', '')
slidenew = {}
slidenew['mac'] = uid
slidenew['id'] = slide['id']
slidenew['name'] = slide['device_name']
slidenew['pos'] = slide['device_info']['pos']
hass.data[DOMAIN][SLIDES][uid] = slidenew

if hass.data[DOMAIN][SLIDES][uid]['pos'] is not None:
if hass.data[DOMAIN][SLIDES][uid]['pos'] < 0:
hass.data[DOMAIN][SLIDES][uid]['pos'] = 0
elif hass.data[DOMAIN][SLIDES][uid]['pos'] > 1:
hass.data[DOMAIN][SLIDES][uid]['pos'] = 1
else:
if 'device_id' not in slide:
_LOGGER.error("Found invalid GoSlide entry, 'device_id' is "
"missing. Entry=%s", slide)
continue

uid = slide['device_id'].replace('slide_', '')
slidenew = {}
slidenew['mac'] = uid
slidenew['id'] = slide['id']
slidenew['name'] = slide['device_name']

if 'device_info' not in slide:
_LOGGER.error("Slide %s (%s) has no 'device_info' Entry=%s",
slide['id'], slidenew['mac'], slide)
continue

# Check if we have 'pos' (OK) or 'code' (NOK)
if 'pos' in slide['device_info']:
slidenew['online'] = True
slidenew['pos'] = slide['device_info']['pos']
if slidenew['pos'] < 0:
slidenew['pos'] = 0
elif slidenew['pos'] > 1:
slidenew['pos'] = 1
elif 'code' in slide['device_info']:
slidenew['online'] = False
_LOGGER.warning("Slide %s (%s) is offline with "
"code=%s",
slide['id'], slidenew['mac'],
slide['device_info']['code'])
else:
slidenew['online'] = False
_LOGGER.error("Slide %s (%s) has invalid 'device_info'"
" %s", slide['id'], slidenew['mac'],
slide['device_info'])

hass.data[DOMAIN][SLIDES][uid] = slidenew
_LOGGER.debug("Updated entry=%s", slidenew)

if DOMAIN not in config:
return True
Expand Down
1 change: 1 addition & 0 deletions goslide/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
COMPONENT = 'cover'
DOMAIN = 'goslide'
SLIDES = 'slides'
STATE_OFFLINE = 'offline'
2 changes: 1 addition & 1 deletion goslide/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from homeassistant.components.cover import (
ENTITY_ID_FORMAT, SUPPORT_CLOSE, SUPPORT_OPEN, SUPPORT_SET_POSITION,
SUPPORT_STOP, STATE_OPEN, STATE_CLOSED, DEVICE_CLASS_CURTAIN, CoverDevice)
from .const import (DOMAIN, SLIDES, API)
from .const import (API, DOMAIN, SLIDES)

_LOGGER = logging.getLogger(__name__)

Expand Down

0 comments on commit 202f413

Please sign in to comment.