mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 14:29:58 +00:00
.devcontainer
.github
.vscode
docs
homeassistant
script
tests
auth
components
abode
adguard
air_quality
airly
alarm_control_panel
alert
alexa
almond
ambiclimate
ambient_station
androidtv
api
api_streams
apns
apprise
aprs
arcam_fmj
arlo
asuswrt
august
aurora
auth
automatic
automation
awair
aws
axis
bayesian
binary_sensor
blackbird
bluetooth_le_tracker
bom
broadlink
brother
buienradar
caldav
calendar
camera
canary
cast
cert_expiry
climate
cloud
coinmarketcap
command_line
config
configurator
conversation
coolmaster
counter
cover
daikin
darksky
datadog
deconz
default_config
demo
denonavr
derivative
device_automation
device_sun_light_trigger
device_tracker
dialogflow
directv
discovery
dsmr
dte_energy_bridge
duckdns
dynalite
dyson
ecobee
ee_brightbox
efergy
elgato
emulated_hue
emulated_roku
esphome
everlights
facebook
facebox
fail2ban
fan
feedreader
ffmpeg
fido
file
filesize
filter
flux
folder
folder_watcher
foobot
freedns
fritzbox
frontend
garmin_connect
gdacs
generic
generic_thermostat
geo_json_events
geo_location
geo_rss_events
geofency
geonetnz_quakes
geonetnz_volcano
gios
glances
google
google_assistant
google_domains
google_pubsub
google_translate
google_wifi
gpslogger
graphite
group
hangouts
hassio
__init__.py
conftest.py
test_addon_panel.py
test_auth.py
test_discovery.py
test_handler.py
test_http.py
test_ingress.py
test_init.py
hddtemp
heos
here_travel_time
hisense_aehw4a1
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
iaqualink
icloud
ifttt
ign_sismologia
image_processing
imap_email_content
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
integration
intent
intent_script
ios
ipma
iqvia
islamic_prayer_times
izone
jewish_calendar
kira
konnected
light
linky
litejet
local_file
local_ip
locative
lock
logbook
logentries
logger
logi_circle
london_air
lovelace
luftdaten
mailbox
mailgun
manual
manual_mqtt
marytts
media_player
melcloud
melissa
meraki
met
meteo_france
mfi
mhz19
microsoft_face
microsoft_face_detect
microsoft_face_identify
mikrotik
min_max
minecraft_server
minio
mobile_app
mochad
modbus
mold_indicator
monoprice
moon
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mythicbeastsdns
namecheapdns
neato
ness_alarm
nest
netatmo
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
opnsense
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
ring
rmvtransport
rss_feed_template
safe_mode
samsungtv
scene
script
search
season
sensor
sentry
seventeentrack
shell_command
shopping_list
sigfox
sighthound
signal_messenger
simplisafe
simulated
sleepiq
sma
smartthings
smhi
smtp
snips
solaredge
solarlog
soma
somfy
sonarr
sonos
soundtouch
spaceapi
spc
splunk
spotify
sql
ssdp
starline
startca
statistics
statsd
stream
stt
sun
switch
switcher_kis
system_health
system_log
tcp
teksavvy
tellduslive
template
tesla
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
vera
verisure
version
vesync
vilfo
vizio
voicerss
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
withings
wled
workday
worldclock
wsdot
wunderground
wwlln
xiaomi
xiaomi_miio
yamaha
yandex_transport
yandextts
yessssms
yr
yweather
zeroconf
zha
zone
zwave
__init__.py
conftest.py
fixtures
hassfest
helpers
mock
resources
scripts
test_util
testing_config
util
__init__.py
bandit.yaml
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
.coveragerc
.dockerignore
.gitattributes
.gitignore
.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
codecov.yml
pylintrc
pyproject.toml
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
setup.py
tox.ini
132 lines
4.2 KiB
Python
132 lines
4.2 KiB
Python
"""The tests for the hassio component."""
|
|
|
|
import aiohttp
|
|
import pytest
|
|
|
|
from homeassistant.components.hassio.handler import HassioAPIError
|
|
|
|
|
|
async def test_api_ping(hassio_handler, aioclient_mock):
|
|
"""Test setup with API ping."""
|
|
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
|
|
|
|
assert await hassio_handler.is_connected()
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_ping_error(hassio_handler, aioclient_mock):
|
|
"""Test setup with API ping error."""
|
|
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "error"})
|
|
|
|
assert not (await hassio_handler.is_connected())
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_ping_exeption(hassio_handler, aioclient_mock):
|
|
"""Test setup with API ping exception."""
|
|
aioclient_mock.get("http://127.0.0.1/supervisor/ping", exc=aiohttp.ClientError())
|
|
|
|
assert not (await hassio_handler.is_connected())
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_homeassistant_info(hassio_handler, aioclient_mock):
|
|
"""Test setup with API Home Assistant info."""
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/homeassistant/info",
|
|
json={"result": "ok", "data": {"last_version": "10.0"}},
|
|
)
|
|
|
|
data = await hassio_handler.get_homeassistant_info()
|
|
assert aioclient_mock.call_count == 1
|
|
assert data["last_version"] == "10.0"
|
|
|
|
|
|
async def test_api_homeassistant_info_error(hassio_handler, aioclient_mock):
|
|
"""Test setup with API Home Assistant info error."""
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/homeassistant/info", json={"result": "error", "message": None}
|
|
)
|
|
|
|
with pytest.raises(HassioAPIError):
|
|
await hassio_handler.get_homeassistant_info()
|
|
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_homeassistant_stop(hassio_handler, aioclient_mock):
|
|
"""Test setup with API Home Assistant stop."""
|
|
aioclient_mock.post("http://127.0.0.1/homeassistant/stop", json={"result": "ok"})
|
|
|
|
assert await hassio_handler.stop_homeassistant()
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_homeassistant_restart(hassio_handler, aioclient_mock):
|
|
"""Test setup with API Home Assistant restart."""
|
|
aioclient_mock.post("http://127.0.0.1/homeassistant/restart", json={"result": "ok"})
|
|
|
|
assert await hassio_handler.restart_homeassistant()
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_addon_info(hassio_handler, aioclient_mock):
|
|
"""Test setup with API Add-on info."""
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/addons/test/info",
|
|
json={"result": "ok", "data": {"name": "bla"}},
|
|
)
|
|
|
|
data = await hassio_handler.get_addon_info("test")
|
|
assert data["name"] == "bla"
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_discovery_message(hassio_handler, aioclient_mock):
|
|
"""Test setup with API discovery message."""
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/discovery/test",
|
|
json={"result": "ok", "data": {"service": "mqtt"}},
|
|
)
|
|
|
|
data = await hassio_handler.get_discovery_message("test")
|
|
assert data["service"] == "mqtt"
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_retrieve_discovery(hassio_handler, aioclient_mock):
|
|
"""Test setup with API discovery message."""
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/discovery",
|
|
json={"result": "ok", "data": {"discovery": [{"service": "mqtt"}]}},
|
|
)
|
|
|
|
data = await hassio_handler.retrieve_discovery_messages()
|
|
assert data["discovery"][-1]["service"] == "mqtt"
|
|
assert aioclient_mock.call_count == 1
|
|
|
|
|
|
async def test_api_ingress_panels(hassio_handler, aioclient_mock):
|
|
"""Test setup with API Ingress panels."""
|
|
aioclient_mock.get(
|
|
"http://127.0.0.1/ingress/panels",
|
|
json={
|
|
"result": "ok",
|
|
"data": {
|
|
"panels": {
|
|
"slug": {
|
|
"enable": True,
|
|
"title": "Test",
|
|
"icon": "mdi:test",
|
|
"admin": False,
|
|
}
|
|
}
|
|
},
|
|
},
|
|
)
|
|
|
|
data = await hassio_handler.get_ingress_panels()
|
|
assert aioclient_mock.call_count == 1
|
|
assert data["panels"]
|
|
assert "slug" in data["panels"]
|