mirror of
https://github.com/home-assistant/core.git
synced 2025-08-18 01:40:11 +00:00
.devcontainer
.github
.vscode
docs
homeassistant
auth
components
abode
accuweather
acer_projector
acmeda
actiontec
adguard
ads
advantage_air
aemet
aftership
agent_dvr
air_quality
airly
airnow
airvisual
aladdin_connect
alarm_control_panel
alarmdecoder
alert
alexa
almond
alpha_vantage
amazon_polly
ambiclimate
ambient_station
amcrest
ampio
analytics
android_ip_webcam
androidtv
anel_pwrctrl
anthemav
apache_kafka
apcupsd
api
apns
apple_tv
apprise
aprs
aqualogic
aquostv
arcam_fmj
arduino
arest
arlo
arris_tg2492lg
aruba
arwn
asterisk_cdr
asterisk_mbox
asuswrt
atag
aten_pe
atome
august
aurora
aurora_abb_powerone
auth
automation
avea
avion
awair
aws
axis
azure_devops
azure_event_hub
azure_service_bus
baidu
bayesian
bbb_gpio
bbox
beewi_smartclim
bh1750
binary_sensor
bitcoin
bizkaibus
blackbird
blebox
blink
blinksticklight
blinkt
blockchain
bloomsky
blueprint
bluesound
bluetooth_le_tracker
bluetooth_tracker
bme280
bme680
bmp280
bmw_connected_drive
bond
braviatv
broadlink
brother
brottsplatskartan
browser
brunt
bsblan
bt_home_hub_5
bt_smarthub
buienradar
caldav
calendar
camera
canary
cast
cert_expiry
channels
circuit
cisco_ios
cisco_mobility_express
cisco_webex_teams
citybikes
clementine
clickatell
clicksend
clicksend_tts
climacell
climate
cloud
cloudflare
cmus
co2signal
coinbase
color_extractor
comed_hourly_pricing
comfoconnect
command_line
compensation
concord232
config
configurator
control4
conversation
coolmaster
coronavirus
counter
cover
cppm_tracker
cpuspeed
cups
currencylayer
daikin
danfoss_air
darksky
datadog
ddwrt
debugpy
deconz
decora
decora_wifi
default_config
delijn
deluge
demo
denon
denonavr
derivative
deutsche_bahn
device_automation
device_sun_light_trigger
device_tracker
devolo_home_control
dexcom
dhcp
dht
dialogflow
digital_ocean
digitalloggers
directv
discogs
discord
discovery
dlib_face_detect
dlib_face_identify
dlink
dlna_dmr
dnsip
dominos
doods
doorbird
dovado
downloader
dsmr
dsmr_reader
dte_energy_bridge
dublin_bus_transport
duckdns
dunehd
dwd_weather_warnings
dweet
dynalite
dyson
eafm
ebox
ebusd
ecoal_boiler
ecobee
econet
ecovacs
eddystone_temperature
edimax
edl21
ee_brightbox
efergy
egardia
eight_sleep
elgato
eliqonline
elkm1
elv
emby
emoncms
emoncms_history
emonitor
emulated_hue
emulated_kasa
emulated_roku
enigma2
enocean
enphase_envoy
entur_public_transport
environment_canada
envirophat
envisalink
ephember
epson
epsonworkforce
eq3btsmart
esphome
essent
etherscan
eufy
everlights
evohome
ezviz
faa_delays
facebook
facebox
fail2ban
familyhub
fan
fastdotcom
feedreader
ffmpeg
ffmpeg_motion
ffmpeg_noise
fibaro
fido
file
filesize
filter
fints
fireservicerota
firmata
fitbit
fixer
fleetgo
flexit
flic
flick_electric
flo
flock
flume
flunearyou
flux
flux_led
folder
folder_watcher
foobot
forked_daapd
fortios
foscam
foursquare
free_mobile
freebox
freedns
fritz
fritzbox
fritzbox_callmonitor
fritzbox_netmonitor
fronius
frontend
frontier_silicon
futurenow
garadget
garmin_connect
gc100
gdacs
generic
generic_thermostat
geniushub
geo_json_events
geo_location
geo_rss_events
geofency
geonetnz_quakes
geonetnz_volcano
gios
github
gitlab_ci
gitter
glances
gntp
goalfeed
goalzero
gogogate2
google
google_assistant
google_cloud
google_domains
google_maps
google_pubsub
google_translate
google_travel_time
google_wifi
gpmdp
gpsd
gpslogger
graphite
gree
greeneye_monitor
greenwave
group
growatt_server
gstreamer
gtfs
guardian
habitica
hangouts
harman_kardon_avr
harmony
hassio
haveibeenpwned
hddtemp
hdmi_cec
heatmiser
heos
here_travel_time
hikvision
hikvisioncam
hisense_aehw4a1
history
history_stats
hitron_coda
hive
hlk_sw16
home_connect
home_plus_control
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
homeworks
honeywell
horizon
hp_ilo
html5
http
htu21d
huawei_lte
huawei_router
hue
huisbaasje
humidifier
hunterdouglas_powerview
hvv_departures
hydrawise
hyperion
iammeter
iaqualink
icloud
idteck_prox
ifttt
iglo
ign_sismologia
ihc
image
image_processing
imap
imap_email_content
incomfort
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
insteon
integration
intent
intent_script
intesishome
ios
iota
iperf3
ipma
ipp
iqvia
irish_rail_transport
islamic_prayer_times
iss
isy994
itach
itunes
izone
jewish_calendar
joaoapps_join
juicenet
kaiterra
kankun
keba
keenetic_ndms2
kef
keyboard
keyboard_remote
kira
kiwi
kmtronic
knx
kodi
konnected
kostal_plenticore
kulersky
kwb
lacrosse
lametric
lannouncer
lastfm
launch_library
lcn
lg_netcast
lg_soundbar
life360
lifx
lifx_cloud
lifx_legacy
light
lightwave
limitlessled
linksys_smart
linode
linux_battery
lirc
litejet
litterrobot
llamalab_automate
local_file
local_ip
locative
lock
logbook
logentries
logger
logi_circle
london_air
london_underground
loopenergy
lovelace
luci
luftdaten
lupusec
lutron
lutron_caseta
lw12wifi
lyft
lyric
magicseaweed
mailbox
mailgun
manual
manual_mqtt
map
marytts
mastodon
matrix
maxcube
mazda
mcp23017
media_extractor
media_player
media_source
mediaroom
melcloud
melissa
meraki
message_bird
met
met_eireann
meteo_france
meteoalarm
metoffice
mfi
mhz19
microsoft
microsoft_face
microsoft_face_detect
microsoft_face_identify
miflora
mikrotik
mill
min_max
minecraft_server
minio
mitemp_bt
mjpeg
mobile_app
mochad
modbus
modem_callerid
mold_indicator
monoprice
moon
motion_blinds
mpchc
mpd
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
msteams
mullvad
mvglive
my
mychevy
mycroft
myq
mysensors
mystrom
mythicbeastsdns
n26
nad
namecheapdns
nanoleaf
neato
nederlandse_spoorwegen
nello
ness_alarm
nest
netatmo
netdata
netgear
netgear_lte
netio
neurio_energy
nexia
nextbus
nextcloud
nfandroidtv
nightscout
niko_home_control
nilu
nissan_leaf
nmap_tracker
nmbs
no_ip
noaa_tides
norway_air
notify
notify_events
notion
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nuki
numato
number
nut
nws
nx584
nzbget
oasa_telematics
obihai
octoprint
oem
ohmconnect
ombi
omnilogic
onboarding
ondilo_ico
onewire
onkyo
onvif
openalpr_cloud
openalpr_local
opencv
openerz
openevse
openexchangerates
opengarage
openhardwaremonitor
openhome
opensensemap
opensky
opentherm_gw
openuv
openweathermap
opnsense
opple
orangepi_gpio
oru
orvibo
osramlightify
otp
ovo_energy
owntracks
ozw
panasonic_bluray
panasonic_viera
pandora
panel_custom
panel_iframe
pcal9535a
pencom
persistent_notification
person
philips_js
pi4ioe5v9xxxx
pi_hole
picotts
piglow
pilight
ping
pioneer
pjlink
plaato
plant
plex
plugwise
plum_lightpad
pocketcasts
point
poolsense
powerwall
profiler
progettihwsw
proliphix
prometheus
prowl
proximity
proxmoxve
proxy
ps4
pulseaudio_loopback
push
pushbullet
pushover
pushsafer
pvoutput
pvpc_hourly_pricing
pyload
python_script
qbittorrent
qld_bushfire
qnap
qrcode
quantum_gateway
qvr_pro
qwikswitch
rachio
radarr
radiotherm
rainbird
raincloud
rainforest_eagle
rainmachine
random
raspihats
raspyrfm
recollect_waste
recorder
recswitch
reddit
rejseplanen
remember_the_milk
remote
remote_rpi_gpio
repetier
rest
rest_command
rflink
rfxtrx
ring
ripple
risco
rituals_perfume_genie
rmvtransport
rocketchat
roku
roomba
roon
route53
rova
rpi_camera
rpi_gpio
rpi_gpio_pwm
rpi_pfio
rpi_power
rpi_rf
rss_feed_template
rtorrent
ruckus_unleashed
russound_rio
russound_rnet
sabnzbd
safe_mode
saj
samsungtv
satel_integra
scene
schluter
scrape
screenlogic
script
scsgate
search
season
sendgrid
sense
sensehat
sensibo
sensor
sentry
serial
serial_pm
sesame
seven_segments
seventeentrack
sharkiq
shell_command
shelly
shiftr
shodan
shopping_list
sht31
sigfox
sighthound
signal_messenger
simplepush
simplisafe
simulated
sinch
sisyphus
sky_hub
skybeacon
skybell
slack
sleepiq
slide
sma
smappee
smart_meter_texas
smarthab
smartthings
smarttub
smarty
smhi
sms
smtp
snapcast
snips
snmp
sochain
solaredge
solaredge_local
solarlog
solax
soma
somfy
somfy_mylink
sonarr
songpal
sonos
sony_projector
soundtouch
spaceapi
spc
speedtestdotnet
spider
splunk
spotcrime
spotify
sql
squeezebox
srp_energy
ssdp
starline
starlingbank
startca
statistics
statsd
steam_online
stiebel_eltron
stookalert
stream
streamlabswater
stt
subaru
suez_water
sun
supervisord
supla
surepetcare
swiss_hydrological_data
swiss_public_transport
swisscom
switch
switchbot
switcher_kis
switchmate
syncthru
synology_chat
synology_dsm
synology_srm
syslog
system_health
system_log
systemmonitor
tado
tag
tahoma
tank_utility
tankerkoenig
tapsaff
tasmota
tautulli
tcp
ted5000
telegram
telegram_bot
tellduslive
tellstick
telnet
temper
template
tensorflow
tesla
tfiac
thermoworks_smoke
thethingsnetwork
thingspeak
thinkingcleaner
thomson
threshold
tibber
tikteck
tile
time_date
timer
tmb
tod
todoist
tof
tomato
toon
torque
totalconnect
touchline
tplink
tplink_lte
traccar
trace
trackr
tradfri
trafikverket_train
trafikverket_weatherstation
transmission
transport_nsw
travisci
trend
tts
tuya
twentemilieu
twilio
twilio_call
twilio_sms
twinkly
twitch
twitter
ubus
ue_smart_radio
uk_transport
unifi
unifi_direct
unifiled
universal
upb
upc_connect
upcloud
updater
upnp
uptime
uptimerobot
uscis
usgs_earthquakes_feed
utility_meter
uvc
vacuum
vallox
vasttrafik
velbus
velux
venstar
vera
verisure
versasense
version
vesync
viaggiatreno
vicare
vilfo
vivotek
vizio
vlc
vlc_telnet
voicerss
volkszaehler
volumio
volvooncall
vultr
w800rf32
wake_on_lan
waqi
water_heater
waterfurnace
watson_iot
watson_tts
waze_travel_time
weather
webhook
webostv
websocket_api
wemo
whois
wiffi
wilight
wink
wirelesstag
withings
wled
wolflink
workday
worldclock
worldtidesinfo
worxlandroid
wsdot
wunderground
x10
xbee
xbox
xbox_live
xeoma
xiaomi
xiaomi_aqara
xiaomi_miio
xiaomi_tv
xmpp
xs1
yale_smart_alarm
yamaha
yamaha_musiccast
yandex_transport
yandextts
yeelight
yeelightsunflower
yi
zabbix
zamg
zengge
zeroconf
zerproc
zestimate
zha
core
translations
__init__.py
api.py
binary_sensor.py
climate.py
config_flow.py
cover.py
device_action.py
device_tracker.py
device_trigger.py
entity.py
fan.py
light.py
lock.py
manifest.json
number.py
sensor.py
services.yaml
strings.json
switch.py
zhong_hong
ziggo_mediabox_xl
zodiac
zone
zoneminder
zwave
zwave_js
__init__.py
generated
helpers
scripts
util
__init__.py
__main__.py
block_async_io.py
bootstrap.py
config.py
config_entries.py
const.py
core.py
data_entry_flow.py
exceptions.py
loader.py
package_constraints.txt
requirements.py
runner.py
setup.py
strings.json
machine
pylint
rootfs
script
tests
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hadolint.yaml
.ignore
.pre-commit-config.yaml
.prettierignore
.readthedocs.yml
.yamllint
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
azure-pipelines-ci.yml
azure-pipelines-release.yml
azure-pipelines-translation.yml
azure-pipelines-wheels.yml
build.json
codecov.yml
pyproject.toml
requirements.txt
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
setup.py
tox.ini
312 lines
10 KiB
Python
312 lines
10 KiB
Python
"""Support for ZHA covers."""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import functools
|
|
import logging
|
|
|
|
from zigpy.zcl.foundation import Status
|
|
|
|
from homeassistant.components.cover import (
|
|
ATTR_CURRENT_POSITION,
|
|
ATTR_POSITION,
|
|
DEVICE_CLASS_DAMPER,
|
|
DEVICE_CLASS_SHADE,
|
|
DOMAIN,
|
|
CoverEntity,
|
|
)
|
|
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING
|
|
from homeassistant.core import callback
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
|
|
from .core import discovery
|
|
from .core.const import (
|
|
CHANNEL_COVER,
|
|
CHANNEL_LEVEL,
|
|
CHANNEL_ON_OFF,
|
|
CHANNEL_SHADE,
|
|
DATA_ZHA,
|
|
DATA_ZHA_DISPATCHERS,
|
|
SIGNAL_ADD_ENTITIES,
|
|
SIGNAL_ATTR_UPDATED,
|
|
SIGNAL_SET_LEVEL,
|
|
)
|
|
from .core.registries import ZHA_ENTITIES
|
|
from .core.typing import ChannelType, ZhaDeviceType
|
|
from .entity import ZhaEntity
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN)
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
"""Set up the Zigbee Home Automation cover from config entry."""
|
|
entities_to_create = hass.data[DATA_ZHA][DOMAIN]
|
|
|
|
unsub = async_dispatcher_connect(
|
|
hass,
|
|
SIGNAL_ADD_ENTITIES,
|
|
functools.partial(
|
|
discovery.async_add_entities, async_add_entities, entities_to_create
|
|
),
|
|
)
|
|
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
|
|
|
|
|
|
@STRICT_MATCH(channel_names=CHANNEL_COVER)
|
|
class ZhaCover(ZhaEntity, CoverEntity):
|
|
"""Representation of a ZHA cover."""
|
|
|
|
def __init__(self, unique_id, zha_device, channels, **kwargs):
|
|
"""Init this sensor."""
|
|
super().__init__(unique_id, zha_device, channels, **kwargs)
|
|
self._cover_channel = self.cluster_channels.get(CHANNEL_COVER)
|
|
self._current_position = None
|
|
|
|
async def async_added_to_hass(self):
|
|
"""Run when about to be added to hass."""
|
|
await super().async_added_to_hass()
|
|
self.async_accept_signal(
|
|
self._cover_channel, SIGNAL_ATTR_UPDATED, self.async_set_position
|
|
)
|
|
|
|
@callback
|
|
def async_restore_last_state(self, last_state):
|
|
"""Restore previous state."""
|
|
self._state = last_state.state
|
|
if "current_position" in last_state.attributes:
|
|
self._current_position = last_state.attributes["current_position"]
|
|
|
|
@property
|
|
def is_closed(self):
|
|
"""Return if the cover is closed."""
|
|
if self.current_cover_position is None:
|
|
return None
|
|
return self.current_cover_position == 0
|
|
|
|
@property
|
|
def is_opening(self):
|
|
"""Return if the cover is opening or not."""
|
|
return self._state == STATE_OPENING
|
|
|
|
@property
|
|
def is_closing(self):
|
|
"""Return if the cover is closing or not."""
|
|
return self._state == STATE_CLOSING
|
|
|
|
@property
|
|
def current_cover_position(self):
|
|
"""Return the current position of ZHA cover.
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
"""
|
|
return self._current_position
|
|
|
|
@callback
|
|
def async_set_position(self, attr_id, attr_name, value):
|
|
"""Handle position update from channel."""
|
|
_LOGGER.debug("setting position: %s", value)
|
|
self._current_position = 100 - value
|
|
if self._current_position == 0:
|
|
self._state = STATE_CLOSED
|
|
elif self._current_position == 100:
|
|
self._state = STATE_OPEN
|
|
self.async_write_ha_state()
|
|
|
|
@callback
|
|
def async_update_state(self, state):
|
|
"""Handle state update from channel."""
|
|
_LOGGER.debug("state=%s", state)
|
|
self._state = state
|
|
self.async_write_ha_state()
|
|
|
|
async def async_open_cover(self, **kwargs):
|
|
"""Open the window cover."""
|
|
res = await self._cover_channel.up_open()
|
|
if isinstance(res, list) and res[1] is Status.SUCCESS:
|
|
self.async_update_state(STATE_OPENING)
|
|
|
|
async def async_close_cover(self, **kwargs):
|
|
"""Close the window cover."""
|
|
res = await self._cover_channel.down_close()
|
|
if isinstance(res, list) and res[1] is Status.SUCCESS:
|
|
self.async_update_state(STATE_CLOSING)
|
|
|
|
async def async_set_cover_position(self, **kwargs):
|
|
"""Move the roller shutter to a specific position."""
|
|
new_pos = kwargs[ATTR_POSITION]
|
|
res = await self._cover_channel.go_to_lift_percentage(100 - new_pos)
|
|
if isinstance(res, list) and res[1] is Status.SUCCESS:
|
|
self.async_update_state(
|
|
STATE_CLOSING if new_pos < self._current_position else STATE_OPENING
|
|
)
|
|
|
|
async def async_stop_cover(self, **kwargs):
|
|
"""Stop the window cover."""
|
|
res = await self._cover_channel.stop()
|
|
if isinstance(res, list) and res[1] is Status.SUCCESS:
|
|
self._state = STATE_OPEN if self._current_position > 0 else STATE_CLOSED
|
|
self.async_write_ha_state()
|
|
|
|
async def async_update(self):
|
|
"""Attempt to retrieve the open/close state of the cover."""
|
|
await super().async_update()
|
|
await self.async_get_state()
|
|
|
|
async def async_get_state(self, from_cache=True):
|
|
"""Fetch the current state."""
|
|
_LOGGER.debug("polling current state")
|
|
if self._cover_channel:
|
|
pos = await self._cover_channel.get_attribute_value(
|
|
"current_position_lift_percentage", from_cache=from_cache
|
|
)
|
|
_LOGGER.debug("read pos=%s", pos)
|
|
|
|
if pos is not None:
|
|
self._current_position = 100 - pos
|
|
self._state = (
|
|
STATE_OPEN if self.current_cover_position > 0 else STATE_CLOSED
|
|
)
|
|
else:
|
|
self._current_position = None
|
|
self._state = None
|
|
|
|
|
|
@STRICT_MATCH(channel_names={CHANNEL_LEVEL, CHANNEL_ON_OFF, CHANNEL_SHADE})
|
|
class Shade(ZhaEntity, CoverEntity):
|
|
"""ZHA Shade."""
|
|
|
|
def __init__(
|
|
self,
|
|
unique_id: str,
|
|
zha_device: ZhaDeviceType,
|
|
channels: list[ChannelType],
|
|
**kwargs,
|
|
):
|
|
"""Initialize the ZHA light."""
|
|
super().__init__(unique_id, zha_device, channels, **kwargs)
|
|
self._on_off_channel = self.cluster_channels[CHANNEL_ON_OFF]
|
|
self._level_channel = self.cluster_channels[CHANNEL_LEVEL]
|
|
self._position = None
|
|
self._is_open = None
|
|
|
|
@property
|
|
def current_cover_position(self):
|
|
"""Return current position of cover.
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
"""
|
|
return self._position
|
|
|
|
@property
|
|
def device_class(self) -> str | None:
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
return DEVICE_CLASS_SHADE
|
|
|
|
@property
|
|
def is_closed(self) -> bool | None:
|
|
"""Return True if shade is closed."""
|
|
if self._is_open is None:
|
|
return None
|
|
return not self._is_open
|
|
|
|
async def async_added_to_hass(self):
|
|
"""Run when about to be added to hass."""
|
|
await super().async_added_to_hass()
|
|
self.async_accept_signal(
|
|
self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_open_closed
|
|
)
|
|
self.async_accept_signal(
|
|
self._level_channel, SIGNAL_SET_LEVEL, self.async_set_level
|
|
)
|
|
|
|
@callback
|
|
def async_restore_last_state(self, last_state):
|
|
"""Restore previous state."""
|
|
self._is_open = last_state.state == STATE_OPEN
|
|
if ATTR_CURRENT_POSITION in last_state.attributes:
|
|
self._position = last_state.attributes[ATTR_CURRENT_POSITION]
|
|
|
|
@callback
|
|
def async_set_open_closed(self, attr_id: int, attr_name: str, value: bool) -> None:
|
|
"""Set open/closed state."""
|
|
self._is_open = bool(value)
|
|
self.async_write_ha_state()
|
|
|
|
@callback
|
|
def async_set_level(self, value: int) -> None:
|
|
"""Set the reported position."""
|
|
value = max(0, min(255, value))
|
|
self._position = int(value * 100 / 255)
|
|
self.async_write_ha_state()
|
|
|
|
async def async_open_cover(self, **kwargs):
|
|
"""Open the window cover."""
|
|
res = await self._on_off_channel.on()
|
|
if not isinstance(res, list) or res[1] != Status.SUCCESS:
|
|
self.debug("couldn't open cover: %s", res)
|
|
return
|
|
|
|
self._is_open = True
|
|
self.async_write_ha_state()
|
|
|
|
async def async_close_cover(self, **kwargs):
|
|
"""Close the window cover."""
|
|
res = await self._on_off_channel.off()
|
|
if not isinstance(res, list) or res[1] != Status.SUCCESS:
|
|
self.debug("couldn't open cover: %s", res)
|
|
return
|
|
|
|
self._is_open = False
|
|
self.async_write_ha_state()
|
|
|
|
async def async_set_cover_position(self, **kwargs):
|
|
"""Move the roller shutter to a specific position."""
|
|
new_pos = kwargs[ATTR_POSITION]
|
|
res = await self._level_channel.move_to_level_with_on_off(
|
|
new_pos * 255 / 100, 1
|
|
)
|
|
|
|
if not isinstance(res, list) or res[1] != Status.SUCCESS:
|
|
self.debug("couldn't set cover's position: %s", res)
|
|
return
|
|
|
|
self._position = new_pos
|
|
self.async_write_ha_state()
|
|
|
|
async def async_stop_cover(self, **kwargs) -> None:
|
|
"""Stop the cover."""
|
|
res = await self._level_channel.stop()
|
|
if not isinstance(res, list) or res[1] != Status.SUCCESS:
|
|
self.debug("couldn't stop cover: %s", res)
|
|
return
|
|
|
|
|
|
@STRICT_MATCH(
|
|
channel_names={CHANNEL_LEVEL, CHANNEL_ON_OFF}, manufacturers="Keen Home Inc"
|
|
)
|
|
class KeenVent(Shade):
|
|
"""Keen vent cover."""
|
|
|
|
@property
|
|
def device_class(self) -> str | None:
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
return DEVICE_CLASS_DAMPER
|
|
|
|
async def async_open_cover(self, **kwargs):
|
|
"""Open the cover."""
|
|
position = self._position or 100
|
|
tasks = [
|
|
self._level_channel.move_to_level_with_on_off(position * 255 / 100, 1),
|
|
self._on_off_channel.on(),
|
|
]
|
|
results = await asyncio.gather(*tasks, return_exceptions=True)
|
|
if any(isinstance(result, Exception) for result in results):
|
|
self.debug("couldn't open cover")
|
|
return
|
|
|
|
self._is_open = True
|
|
self._position = position
|
|
self.async_write_ha_state()
|