Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ omit =
homeassistant/components/climate/touchline.py
homeassistant/components/climate/venstar.py
homeassistant/components/climate/zhong_hong.py
homeassistant/components/cover/aladdin_connect.py
homeassistant/components/cover/brunt.py
homeassistant/components/cover/garadget.py
homeassistant/components/cover/gogogate2.py
Expand Down
105 changes: 105 additions & 0 deletions homeassistant/components/cover/aladdin_connect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import logging

This comment was marked as resolved.


import voluptuous as vol

from homeassistant.components.cover import (CoverDevice, PLATFORM_SCHEMA,
SUPPORT_OPEN, SUPPORT_CLOSE)
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, STATE_CLOSED,
STATE_OPENING, STATE_CLOSING, STATE_UNKNOWN)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['aladdin_connect==0.1']

_LOGGER = logging.getLogger(__name__)

NOTIFICATION_ID = 'aladdin_notification'
NOTIFICATION_TITLE = 'Aladdin Connect Cover Setup'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Aladdin Connect component."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a platform not a component.

from aladdin_connect import AladdinConnectClient

username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
acc = AladdinConnectClient(username, password)

try:
if not acc.login():
raise ValueError("Username or Password is incorrect")
add_devices(AladdinDevice(acc, door) for door in acc.get_doors())
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. Nothing is checking this return value.

except (TypeError, KeyError, NameError, ValueError) as ex:
_LOGGER.error("%s", ex)
hass.components.persistent_notification.create(
'Error: {}<br />'
'You will need to restart hass after fixing.'
''.format(ex),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.



class AladdinDevice(CoverDevice):
"""Representation of Aladdin Connect cover"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period at the end of the docstring.


def __init__(self, acc, device):
self._acc = acc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring.

self._device_id = device['device_id']
self._number = device['door_number']
self._name = device['name']
self._status = device['status']

@property
def device_class(self):
"""Define this cover as a garage door."""
return 'garage'

@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_OPEN | SUPPORT_CLOSE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be extracted to constant put at the module level and returned here.


@property
def should_poll(self):
"""Poll for state."""
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default. We can remove this property.


@property
def name(self):
"""Return the name of the garage door."""
return self._name

@property
def is_opening(self):
"""Return if the cover is opening or not."""
return self._status == STATE_OPENING

This comment was marked as resolved.


@property
def is_closing(self):
"""Return if the cover is closing or not."""
return self._status == STATE_CLOSING

@property
def is_closed(self):
"""Return None if status is unknown, true if closed, else False."""
if self._status == STATE_UNKNOWN:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if self._status is None:
    return None

return None
return self._status == STATE_CLOSED

def close_cover(self, **kwargs):
"""Issue close command to cover."""
self._acc.close_door(self._device_id, self._number)

def open_cover(self, **kwargs):
"""Issue open command to cover."""
self._acc.open_door(self._device_id, self._number)

def update(self):
"""Update status of cover."""
self._status = self._acc.get_door_status(self._device_id, self._number)
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Adafruit-SHT31==1.0.2
# homeassistant.components.sensor.dht
# Adafruit_Python_DHT==1.3.2

# homeassistant.components.cover.aladdin_connect
aladdin_connect==0.1

# homeassistant.components.doorbird
DoorBirdPy==0.1.3

Expand Down