Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 23 additions & 7 deletions homeassistant/components/slide/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Component for the Go Slide API."""
"""Component for the Slide API."""

from datetime import timedelta
import logging
Expand All @@ -19,7 +19,15 @@
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.event import async_call_later, async_track_time_interval

from .const import API, COMPONENT, DEFAULT_RETRY, DOMAIN, SLIDES
from .const import (
API,
COMPONENT,
CONF_INVERT_POSITION,
DEFAULT_OFFSET,
DEFAULT_RETRY,
DOMAIN,
SLIDES,
)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -34,6 +42,7 @@
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): cv.time_period,
vol.Optional(CONF_INVERT_POSITION, default=False): cv.boolean,
}
)
},
Expand All @@ -60,7 +69,7 @@ async def update_slides(now=None):
for slide in result:
if "device_id" not in slide:
_LOGGER.error(
"Found invalid Slide entry, device_id is missing. Entry=%s", slide,
"Found invalid Slide entry, device_id is missing. Entry=%s", slide
)
continue

Expand All @@ -73,6 +82,7 @@ async def update_slides(now=None):
oldpos = slidenew.get("pos")
slidenew["pos"] = None
slidenew["online"] = False
slidenew["invert"] = config[DOMAIN][CONF_INVERT_POSITION]

if "device_info" not in slide:
_LOGGER.error(
Expand All @@ -91,15 +101,21 @@ async def update_slides(now=None):

if oldpos is None or oldpos == slidenew["pos"]:
slidenew["state"] = (
STATE_CLOSED if slidenew["pos"] > 0.95 else STATE_OPEN
STATE_CLOSED
if slidenew["pos"] > (1 - DEFAULT_OFFSET)
else STATE_OPEN
)
elif oldpos < slidenew["pos"]:
slidenew["state"] = (
STATE_CLOSED if slidenew["pos"] >= 0.95 else STATE_CLOSING
STATE_CLOSED
if slidenew["pos"] >= (1 - DEFAULT_OFFSET)
else STATE_CLOSING
)
else:
slidenew["state"] = (
STATE_OPEN if slidenew["pos"] <= 0.05 else STATE_OPENING
STATE_OPEN
if slidenew["pos"] <= DEFAULT_OFFSET
else STATE_OPENING
)
elif "code" in slide["device_info"]:
_LOGGER.warning(
Expand Down Expand Up @@ -135,7 +151,7 @@ async def retry_setup(now):
result = await hass.data[DOMAIN][API].login()
except (goslideapi.ClientConnectionError, goslideapi.ClientTimeoutError) as err:
_LOGGER.error(
"Error connecting to Slide Cloud: %s, going to retry in %s seconds",
"Error connecting to Slide Cloud: %s, going to retry in %s second(s)",
err,
DEFAULT_RETRY,
)
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/slide/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Define constants for the Go Slide component."""
"""Define constants for the Slide component."""

API = "api"
COMPONENT = "cover"
CONF_INVERT_POSITION = "invert_position"
DOMAIN = "slide"
SLIDES = "slides"
DEFAULT_OFFSET = 0.15
DEFAULT_RETRY = 120
15 changes: 11 additions & 4 deletions homeassistant/components/slide/cover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Support for Go Slide slides."""
"""Support for Slide slides."""

import logging

Expand All @@ -12,13 +12,13 @@
)
from homeassistant.const import ATTR_ID

from .const import API, DOMAIN, SLIDES
from .const import API, DEFAULT_OFFSET, DOMAIN, SLIDES

_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up cover(s) for Go Slide platform."""
"""Set up cover(s) for Slide platform."""

if discovery_info is None:
return
Expand All @@ -33,7 +33,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=


class SlideCover(CoverDevice):
"""Representation of a Go Slide cover."""
"""Representation of a Slide cover."""

def __init__(self, api, slide):
"""Initialize the cover."""
Expand All @@ -42,6 +42,7 @@ def __init__(self, api, slide):
self._id = slide["id"]
self._unique_id = slide["mac"]
self._name = slide["name"]
self._invert = slide["invert"]

@property
def unique_id(self):
Expand Down Expand Up @@ -95,6 +96,10 @@ def current_cover_position(self):
"""Return the current position of cover shutter."""
pos = self._slide["pos"]
if pos is not None:
if (1 - pos) <= DEFAULT_OFFSET or pos <= DEFAULT_OFFSET:
pos = round(pos)
if not self._invert:
pos = 1 - pos
pos = int(pos * 100)
return pos

Expand All @@ -115,6 +120,8 @@ async def async_stop_cover(self, **kwargs):
async def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
position = kwargs[ATTR_POSITION] / 100
if not self._invert:
position = 1 - position

if self._slide["pos"] is not None:
if position > self._slide["pos"]:
Expand Down