1
0
mirror of https://github.com/home-assistant/core.git synced 2025-09-02 09:01:05 +00:00
Files
.github
docs
homeassistant
script
tests
auth
components
air_quality
alarm_control_panel
alert
alexa
ambient_station
api
api_streams
apns
arlo
asuswrt
aurora
auth
automatic
automation
awair
aws
axis
bayesian
binary_sensor
blackbird
bom
caldav
calendar
camera
canary
cast
climate
cloud
coinmarketcap
command_line
config
configurator
conversation
counter
cover
daikin
darksky
datadog
deconz
default_config
demo
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
google
google_assistant
google_domains
google_pubsub
google_wifi
gpslogger
graphite
group
hangouts
hassio
hddtemp
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
hydroquebec
ifttt
image_processing
imap_email_content
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
integration
intent_script
introduction
ios
ipma
islamic_prayer_times
jewish_calendar
kira
light
litejet
local_file
locative
lock
logbook
logentries
logger
london_air
lovelace
luftdaten
mailbox
mailgun
manual
manual_mqtt
marytts
media_player
melissa
meraki
mfi
mhz19
microsoft_face
microsoft_face_detect
microsoft_face_identify
min_max
mobile_app
mochad
mold_indicator
monoprice
moon
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mythicbeastsdns
namecheapdns
ness_alarm
nest
no_ip
notify
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nx584
onboarding
openalpr_cloud
openalpr_local
openhardwaremonitor
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pilight
plant
point
prometheus
proximity
ps4
push
pushbullet
python_script
qwikswitch
radarr
rainmachine
random
recorder
reddit
remember_the_milk
remote
rest
rest_command
rflink
rfxtrx
ring
rmvtransport
rss_feed_template
samsungtv
scene
script
season
sensor
shell_command
shopping_list
sigfox
simplisafe
simulated
sleepiq
smartthings
smhi
smtp
snips
sonarr
sonos
soundtouch
spaceapi
spc
splunk
sql
srp_energy
startca
statistics
statsd
stream
sun
switch
system_health
system_log
tcp
teksavvy
tellduslive
template
threshold
time_date
timer
tod
tomato
toon
tplink
tradfri
transport_nsw
trend
tts
twilio
uk_transport
unifi
unifi_direct
universal
upc_connect
updater
upnp
uptime
usgs_earthquakes_feed
utility_meter
uvc
vacuum
verisure
version
voicerss
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
workday
worldclock
wsdot
wunderground
xiaomi
xiaomi_miio
yamaha
yandextts
yessssms
yr
yweather
zha
__init__.py
common.py
conftest.py
test_api.py
test_binary_sensor.py
test_config_flow.py
test_fan.py
test_light.py
test_sensor.py
test_switch.py
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
virtualization
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.readthedocs.yml
.travis.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE.md
MANIFEST.in
README.rst
mypy.ini
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini
core/tests/components/zha/test_api.py
David F. Mulcahey 300384410f Refactor ZHA gateway into modules and add admin protections to API ()
* refactor

* cleanup

* fix tests

* admin all the things
2019-03-14 10:20:25 -04:00

128 lines
3.6 KiB
Python

"""Test ZHA API."""
import pytest
from homeassistant.components.switch import DOMAIN
from homeassistant.components.zha.api import (
async_load_api, ATTR_IEEE, TYPE, ID
)
from homeassistant.components.zha.core.const import (
ATTR_CLUSTER_ID, ATTR_CLUSTER_TYPE, IN, IEEE, MODEL, NAME, QUIRK_APPLIED,
ATTR_MANUFACTURER, ATTR_ENDPOINT_ID
)
from .common import async_init_zigpy_device
@pytest.fixture
async def zha_client(hass, config_entry, zha_gateway, hass_ws_client):
"""Test zha switch platform."""
from zigpy.zcl.clusters.general import OnOff, Basic
# load the ZHA API
async_load_api(hass)
# create zigpy device
await async_init_zigpy_device(
hass, [OnOff.cluster_id, Basic.cluster_id], [], None, zha_gateway)
# load up switch domain
await hass.config_entries.async_forward_entry_setup(
config_entry, DOMAIN)
await hass.async_block_till_done()
return await hass_ws_client(hass)
async def test_device_clusters(hass, config_entry, zha_gateway, zha_client):
"""Test getting device cluster info."""
await zha_client.send_json({
ID: 5,
TYPE: 'zha/devices/clusters',
ATTR_IEEE: '00:0d:6f:00:0a:90:69:e7'
})
msg = await zha_client.receive_json()
assert len(msg['result']) == 2
cluster_infos = sorted(msg['result'], key=lambda k: k[ID])
cluster_info = cluster_infos[0]
assert cluster_info[TYPE] == IN
assert cluster_info[ID] == 0
assert cluster_info[NAME] == 'Basic'
cluster_info = cluster_infos[1]
assert cluster_info[TYPE] == IN
assert cluster_info[ID] == 6
assert cluster_info[NAME] == 'OnOff'
async def test_device_cluster_attributes(
hass, config_entry, zha_gateway, zha_client):
"""Test getting device cluster attributes."""
await zha_client.send_json({
ID: 5,
TYPE: 'zha/devices/clusters/attributes',
ATTR_ENDPOINT_ID: 1,
ATTR_IEEE: '00:0d:6f:00:0a:90:69:e7',
ATTR_CLUSTER_ID: 6,
ATTR_CLUSTER_TYPE: IN
})
msg = await zha_client.receive_json()
attributes = msg['result']
assert len(attributes) == 4
for attribute in attributes:
assert attribute[ID] is not None
assert attribute[NAME] is not None
async def test_device_cluster_commands(
hass, config_entry, zha_gateway, zha_client):
"""Test getting device cluster commands."""
await zha_client.send_json({
ID: 5,
TYPE: 'zha/devices/clusters/commands',
ATTR_ENDPOINT_ID: 1,
ATTR_IEEE: '00:0d:6f:00:0a:90:69:e7',
ATTR_CLUSTER_ID: 6,
ATTR_CLUSTER_TYPE: IN
})
msg = await zha_client.receive_json()
commands = msg['result']
assert len(commands) == 6
for command in commands:
assert command[ID] is not None
assert command[NAME] is not None
assert command[TYPE] is not None
async def test_list_devices(
hass, config_entry, zha_gateway, zha_client):
"""Test getting entity cluster commands."""
await zha_client.send_json({
ID: 5,
TYPE: 'zha/devices'
})
msg = await zha_client.receive_json()
devices = msg['result']
assert len(devices) == 1
for device in devices:
assert device[IEEE] is not None
assert device[ATTR_MANUFACTURER] is not None
assert device[MODEL] is not None
assert device[NAME] is not None
assert device[QUIRK_APPLIED] is not None
assert device['entities'] is not None
for entity_reference in device['entities']:
assert entity_reference[NAME] is not None
assert entity_reference['entity_id'] is not None