mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add support for SOMA Smartshades devices (#26226)
* Add Soma integration * Fixed cover position get/set * Try to list devices before creating config entries to see if Soma Connect can be polled * Style fixes * Updated requirements * Updated .coveragerc to ignore Soma component * Fixed linter errors * Implemented stop command * Test coverage fixes according to feedback * Fixes to code according to feedback * Added error logging and tested config from yaml * Indentation fix * Removed unnecessary method * Wrong indentation * Added some tests * Added test for import step leading to entry creation * Added feedback to user form in case of connection error * Minor fixes according to feedback * Changed exception type in error handling for connection to Connect * To keep API consistent for Google Home and Alexa we swapped the open/closed position values back and I reversed them in this integration as well * regenerated requirements, ran black, addde __init__.py to ignore file * Added pysoma library to gen_requirements_all.py * Added missing test case * removed useless return value
This commit is contained in:
committed by
Martin Hjelmare
parent
21453df73e
commit
48d07467d9
79
homeassistant/components/soma/cover.py
Normal file
79
homeassistant/components/soma/cover.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""Support for Soma Covers."""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.cover import CoverDevice, ATTR_POSITION
|
||||
from homeassistant.components.soma import DOMAIN, SomaEntity, DEVICES, API
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Soma cover platform."""
|
||||
|
||||
devices = hass.data[DOMAIN][DEVICES]
|
||||
|
||||
async_add_entities(
|
||||
[SomaCover(cover, hass.data[DOMAIN][API]) for cover in devices], True
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Old way of setting up platform.
|
||||
|
||||
Can only be called when a user accidentally mentions the platform in their
|
||||
config. But even in that case it would have been ignored.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class SomaCover(SomaEntity, CoverDevice):
|
||||
"""Representation of a Soma cover device."""
|
||||
|
||||
def close_cover(self, **kwargs):
|
||||
"""Close the cover."""
|
||||
response = self.api.set_shade_position(self.device["mac"], 100)
|
||||
if response["result"] != "success":
|
||||
_LOGGER.error(
|
||||
"Unable to reach device %s (%s)", self.device["name"], response["msg"]
|
||||
)
|
||||
|
||||
def open_cover(self, **kwargs):
|
||||
"""Open the cover."""
|
||||
response = self.api.set_shade_position(self.device["mac"], 0)
|
||||
if response["result"] != "success":
|
||||
_LOGGER.error(
|
||||
"Unable to reach device %s (%s)", self.device["name"], response["msg"]
|
||||
)
|
||||
|
||||
def stop_cover(self, **kwargs):
|
||||
"""Stop the cover."""
|
||||
# Set cover position to some value where up/down are both enabled
|
||||
self.current_position = 50
|
||||
response = self.api.stop_shade(self.device["mac"])
|
||||
if response["result"] != "success":
|
||||
_LOGGER.error(
|
||||
"Unable to reach device %s (%s)", self.device["name"], response["msg"]
|
||||
)
|
||||
|
||||
def set_cover_position(self, **kwargs):
|
||||
"""Move the cover shutter to a specific position."""
|
||||
self.current_position = kwargs[ATTR_POSITION]
|
||||
response = self.api.set_shade_position(
|
||||
self.device["mac"], 100 - kwargs[ATTR_POSITION]
|
||||
)
|
||||
if response["result"] != "success":
|
||||
_LOGGER.error(
|
||||
"Unable to reach device %s (%s)", self.device["name"], response["msg"]
|
||||
)
|
||||
|
||||
@property
|
||||
def current_cover_position(self):
|
||||
"""Return the current position of cover shutter."""
|
||||
return self.current_position
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
"""Return if the cover is closed."""
|
||||
return self.current_position == 0
|
||||
Reference in New Issue
Block a user