mirror of
https://github.com/home-assistant/core.git
synced 2025-08-21 19:30:02 +00:00
.devcontainer
.github
.vscode
docs
homeassistant
script
tests
auth
components
adguard
air_quality
airly
alarm_control_panel
alert
alexa
ambiclimate
ambient_station
androidtv
api
api_streams
apns
aprs
arcam_fmj
arlo
asuswrt
aurora
auth
automatic
automation
awair
aws
axis
bayesian
binary_sensor
blackbird
bom
broadlink
buienradar
caldav
calendar
camera
canary
cast
cert_expiry
climate
cloud
coinmarketcap
command_line
config
configurator
conversation
counter
cover
daikin
darksky
datadog
deconz
default_config
demo
device_automation
device_sun_light_trigger
device_tracker
dialogflow
directv
discovery
dsmr
dte_energy_bridge
duckdns
dyson
ecobee
ee_brightbox
efergy
emulated_hue
emulated_roku
esphome
everlights
facebook
facebox
fail2ban
fan
feedreader
ffmpeg
fido
file
filesize
filter
flux
folder
folder_watcher
foobot
freedns
fritzbox
frontend
generic
generic_thermostat
geo_json_events
geo_location
geo_rss_events
geofency
geonetnz_quakes
google
google_assistant
google_domains
google_pubsub
google_translate
google_wifi
gpslogger
graphite
group
hangouts
hassio
hddtemp
heos
here_travel_time
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
hydroquebec
iaqualink
ifttt
ign_sismologia
image_processing
imap_email_content
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
integration
intent_script
ios
ipma
iqvia
islamic_prayer_times
izone
jewish_calendar
kira
light
linky
litejet
local_file
locative
lock
logbook
logentries
logger
logi_circle
london_air
lovelace
luftdaten
mailbox
mailgun
manual
manual_mqtt
marytts
media_player
melissa
meraki
met
mfi
mhz19
microsoft_face
microsoft_face_detect
microsoft_face_identify
min_max
minio
mobile_app
mochad
modbus
mold_indicator
monoprice
moon
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mythicbeastsdns
namecheapdns
neato
ness_alarm
nest
nextbus
no_ip
notify
notion
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nws
nx584
onboarding
openalpr_cloud
openalpr_local
openhardwaremonitor
opentherm_gw
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pi_hole
pilight
plant
plex
point
prometheus
proximity
ps4
ptvsd
push
pushbullet
python_script
qld_bushfire
qwikswitch
radarr
rainmachine
random
recorder
reddit
remember_the_milk
remote
rest
rest_command
rflink
rfxtrx
__init__.py
test_cover.py
test_init.py
test_light.py
test_sensor.py
test_switch.py
ring
rmvtransport
rss_feed_template
samsungtv
scene
script
season
sensor
seventeentrack
shell_command
shopping_list
sigfox
simplisafe
simulated
sleepiq
sma
smartthings
smhi
smtp
snips
solaredge
soma
somfy
sonarr
sonos
soundtouch
spaceapi
spc
splunk
sql
ssdp
startca
statistics
statsd
stream
sun
switch
switcher_kis
system_health
system_log
tcp
teksavvy
tellduslive
template
threshold
time_date
timer
tod
tomato
toon
tplink
traccar
tradfri
transmission
transport_nsw
trend
tts
twentemilieu
twilio
uk_transport
unifi
unifi_direct
universal
updater
upnp
uptime
usgs_earthquakes_feed
utility_meter
uvc
vacuum
velbus
verisure
version
vesync
voicerss
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
withings
workday
worldclock
wsdot
wunderground
wwlln
xiaomi
xiaomi_miio
yamaha
yandex_transport
yandextts
yessssms
yr
yweather
zeroconf
zha
zone
zwave
__init__.py
conftest.py
fixtures
helpers
mock
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_loader.py
test_main.py
test_requirements.py
test_setup.py
.codecov.yml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.pre-commit-config.yaml
.readthedocs.yml
.travis.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
azure-pipelines-ci.yml
azure-pipelines-release.yml
azure-pipelines-translation.yml
azure-pipelines-wheels.yml
mypyrc
pylintrc
pyproject.toml
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini
275 lines
9.0 KiB
Python
275 lines
9.0 KiB
Python
"""The tests for the Rfxtrx cover platform."""
|
|
import unittest
|
|
|
|
import pytest
|
|
|
|
from homeassistant.setup import setup_component
|
|
from homeassistant.components import rfxtrx as rfxtrx_core
|
|
|
|
from tests.common import get_test_home_assistant, mock_component
|
|
|
|
|
|
@pytest.mark.skipif("os.environ.get('RFXTRX') != 'RUN'")
|
|
class TestCoverRfxtrx(unittest.TestCase):
|
|
"""Test the Rfxtrx cover platform."""
|
|
|
|
def setUp(self):
|
|
"""Set up things to be run when tests are started."""
|
|
self.hass = get_test_home_assistant()
|
|
mock_component("rfxtrx")
|
|
|
|
def tearDown(self):
|
|
"""Stop everything that was started."""
|
|
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
|
|
rfxtrx_core.RFX_DEVICES = {}
|
|
if rfxtrx_core.RFXOBJECT:
|
|
rfxtrx_core.RFXOBJECT.close_connection()
|
|
self.hass.stop()
|
|
|
|
def test_valid_config(self):
|
|
"""Test configuration."""
|
|
assert setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"automatic_add": True,
|
|
"devices": {
|
|
"0b1100cd0213c7f210010f51": {
|
|
"name": "Test",
|
|
rfxtrx_core.ATTR_FIREEVENT: True,
|
|
}
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
def test_invalid_config_capital_letters(self):
|
|
"""Test configuration."""
|
|
assert not setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"automatic_add": True,
|
|
"devices": {
|
|
"2FF7f216": {
|
|
"name": "Test",
|
|
"packetid": "0b1100cd0213c7f210010f51",
|
|
"signal_repetitions": 3,
|
|
}
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
def test_invalid_config_extra_key(self):
|
|
"""Test configuration."""
|
|
assert not setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"automatic_add": True,
|
|
"invalid_key": "afda",
|
|
"devices": {
|
|
"213c7f216": {
|
|
"name": "Test",
|
|
"packetid": "0b1100cd0213c7f210010f51",
|
|
rfxtrx_core.ATTR_FIREEVENT: True,
|
|
}
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
def test_invalid_config_capital_packetid(self):
|
|
"""Test configuration."""
|
|
assert not setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"automatic_add": True,
|
|
"devices": {
|
|
"213c7f216": {
|
|
"name": "Test",
|
|
"packetid": "AA1100cd0213c7f210010f51",
|
|
rfxtrx_core.ATTR_FIREEVENT: True,
|
|
}
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
def test_invalid_config_missing_packetid(self):
|
|
"""Test configuration."""
|
|
assert not setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"automatic_add": True,
|
|
"devices": {
|
|
"213c7f216": {"name": "Test", rfxtrx_core.ATTR_FIREEVENT: True}
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
def test_default_config(self):
|
|
"""Test with 0 cover."""
|
|
assert setup_component(
|
|
self.hass, "cover", {"cover": {"platform": "rfxtrx", "devices": {}}}
|
|
)
|
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
def test_one_cover(self):
|
|
"""Test with 1 cover."""
|
|
assert setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"devices": {"0b1400cd0213c7f210010f51": {"name": "Test"}},
|
|
}
|
|
},
|
|
)
|
|
|
|
import RFXtrx as rfxtrxmod
|
|
|
|
rfxtrx_core.RFXOBJECT = rfxtrxmod.Core(
|
|
"", transport_protocol=rfxtrxmod.DummyTransport
|
|
)
|
|
|
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
|
for id in rfxtrx_core.RFX_DEVICES:
|
|
entity = rfxtrx_core.RFX_DEVICES[id]
|
|
assert entity.signal_repetitions == 1
|
|
assert not entity.should_fire_event
|
|
assert not entity.should_poll
|
|
entity.open_cover()
|
|
entity.close_cover()
|
|
entity.stop_cover()
|
|
|
|
def test_several_covers(self):
|
|
"""Test with 3 covers."""
|
|
assert setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{
|
|
"cover": {
|
|
"platform": "rfxtrx",
|
|
"signal_repetitions": 3,
|
|
"devices": {
|
|
"0b1100cd0213c7f230010f71": {"name": "Test"},
|
|
"0b1100100118cdea02010f70": {"name": "Bath"},
|
|
"0b1100101118cdea02010f70": {"name": "Living"},
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
assert 3 == len(rfxtrx_core.RFX_DEVICES)
|
|
device_num = 0
|
|
for id in rfxtrx_core.RFX_DEVICES:
|
|
entity = rfxtrx_core.RFX_DEVICES[id]
|
|
assert entity.signal_repetitions == 3
|
|
if entity.name == "Living":
|
|
device_num = device_num + 1
|
|
elif entity.name == "Bath":
|
|
device_num = device_num + 1
|
|
elif entity.name == "Test":
|
|
device_num = device_num + 1
|
|
|
|
assert 3 == device_num
|
|
|
|
def test_discover_covers(self):
|
|
"""Test with discovery of covers."""
|
|
assert setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{"cover": {"platform": "rfxtrx", "automatic_add": True, "devices": {}}},
|
|
)
|
|
|
|
event = rfxtrx_core.get_rfx_object("0a140002f38cae010f0070")
|
|
event.data = bytearray(
|
|
[0x0A, 0x14, 0x00, 0x02, 0xF3, 0x8C, 0xAE, 0x01, 0x0F, 0x00, 0x70]
|
|
)
|
|
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 1 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
event = rfxtrx_core.get_rfx_object("0a1400adf394ab020e0060")
|
|
event.data = bytearray(
|
|
[0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94, 0xAB, 0x02, 0x0E, 0x00, 0x60]
|
|
)
|
|
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
# Trying to add a sensor
|
|
event = rfxtrx_core.get_rfx_object("0a52085e070100b31b0279")
|
|
event.data = bytearray(b"\nR\x08^\x07\x01\x00\xb3\x1b\x02y")
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
# Trying to add a light
|
|
event = rfxtrx_core.get_rfx_object("0b1100100118cdea02010f70")
|
|
event.data = bytearray(
|
|
[0x0B, 0x11, 0x11, 0x10, 0x01, 0x18, 0xCD, 0xEA, 0x01, 0x02, 0x0F, 0x70]
|
|
)
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 2 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
def test_discover_cover_noautoadd(self):
|
|
"""Test with discovery of cover when auto add is False."""
|
|
assert setup_component(
|
|
self.hass,
|
|
"cover",
|
|
{"cover": {"platform": "rfxtrx", "automatic_add": False, "devices": {}}},
|
|
)
|
|
|
|
event = rfxtrx_core.get_rfx_object("0a1400adf394ab010d0060")
|
|
event.data = bytearray(
|
|
[0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94, 0xAB, 0x01, 0x0D, 0x00, 0x60]
|
|
)
|
|
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
event = rfxtrx_core.get_rfx_object("0a1400adf394ab020e0060")
|
|
event.data = bytearray(
|
|
[0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94, 0xAB, 0x02, 0x0E, 0x00, 0x60]
|
|
)
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
# Trying to add a sensor
|
|
event = rfxtrx_core.get_rfx_object("0a52085e070100b31b0279")
|
|
event.data = bytearray(b"\nR\x08^\x07\x01\x00\xb3\x1b\x02y")
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|
|
|
|
# Trying to add a light
|
|
event = rfxtrx_core.get_rfx_object("0b1100100118cdea02010f70")
|
|
event.data = bytearray(
|
|
[0x0B, 0x11, 0x11, 0x10, 0x01, 0x18, 0xCD, 0xEA, 0x01, 0x02, 0x0F, 0x70]
|
|
)
|
|
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
|
evt_sub(event)
|
|
assert 0 == len(rfxtrx_core.RFX_DEVICES)
|