Skip to content

Commit

Permalink
Changed: Error handling during value update and Slide offline
Browse files Browse the repository at this point in the history
Changed: Local API timeout from 10 to 5 seconds
  • Loading branch information
ualex73 committed May 26, 2024
1 parent aaac17e commit 2575bd3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions custom_components/slide/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def async_setup_platform(

try:
slide_info = await hass.data[DOMAIN][API_LOCAL].slide_info(cover[CONF_HOST])
except (goslideapi.ClientConnectionError) as err:
except (goslideapi.ClientConnectionError, goslideapi.ClientTimeoutError) as err:
# https://developers.home-assistant.io/docs/integration_setup_failures/
raise PlatformNotReady(
f"Unable to setup Slide '{cover[CONF_HOST]}': {err}"
Expand Down Expand Up @@ -348,24 +348,36 @@ async def async_set_cover_position(self, **kwargs: Any) -> None:
async def async_update(self) -> None:
"""Update slide information."""

slide = await self._api.slide_info(self._id)
self.parsedata(slide)
slide_info = None

def parsedata(self, slide) -> None:
try:
slide_info = await self._api.slide_info(self._id)
self.parsedata(slide_info)
except (goslideapi.ClientConnectionError, goslideapi.ClientTimeoutError) as err:
# Set Slide to unavailable
self._slide["online"] = False

_LOGGER.error(
"Unable to get information from Slide '%s': %s",
self._id,
str(err),
)

def parsedata(self, slide_info) -> None:

self._slide["online"] = False

if slide is None:
if slide_info is None:
_LOGGER.error("Slide '%s' returned no data (offline?)", self._id)
return

if "pos" in slide:
if "pos" in slide_info:
if self._unique_id is None:
self._unique_id = slide["slide_id"]
self._unique_id = slide_info["slide_id"]
oldpos = self._slide.get("pos")
self._slide["online"] = True
self._slide["touchgo"] = slide["touch_go"]
self._slide["pos"] = slide["pos"]
self._slide["touchgo"] = slide_info["touch_go"]
self._slide["pos"] = slide_info["pos"]
self._slide["pos"] = max(0, min(1, self._slide["pos"]))

if oldpos is None or oldpos == self._slide["pos"]:
Expand All @@ -387,7 +399,7 @@ def parsedata(self, slide) -> None:
else STATE_OPENING
)
else:
_LOGGER.error("Slide '%s' has invalid data %s", self._id, str(slide))
_LOGGER.error("Slide '%s' has invalid data %s", self._id, str(slide_info))

# The format is:
# {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/slide/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"documentation": "https://www.home-assistant.io/integrations/slide",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/ualex73/slide/issues",
"requirements": ["goslide-api==0.6.9"],
"requirements": ["goslide-api==0.7.0"],
"version": "1.5"
}

0 comments on commit 2575bd3

Please sign in to comment.