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
__init__.py
test_init.py
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
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/lovelace/test_init.py
2019-01-30 12:57:56 -08:00

186 lines
4.9 KiB
Python

"""Test the Lovelace initialization."""
from unittest.mock import patch
from homeassistant.setup import async_setup_component
from homeassistant.components import frontend, lovelace
from tests.common import get_system_health_info
async def test_lovelace_from_storage(hass, hass_ws_client, hass_storage):
"""Test we load lovelace config from storage."""
assert await async_setup_component(hass, 'lovelace', {})
assert hass.data[frontend.DATA_PANELS]['lovelace'].config == {
'mode': 'storage'
}
client = await hass_ws_client(hass)
# Fetch data
await client.send_json({
'id': 5,
'type': 'lovelace/config'
})
response = await client.receive_json()
assert not response['success']
assert response['error']['code'] == 'config_not_found'
# Store new config
await client.send_json({
'id': 6,
'type': 'lovelace/config/save',
'config': {
'yo': 'hello'
}
})
response = await client.receive_json()
assert response['success']
assert hass_storage[lovelace.STORAGE_KEY]['data'] == {
'config': {'yo': 'hello'}
}
# Load new config
await client.send_json({
'id': 7,
'type': 'lovelace/config'
})
response = await client.receive_json()
assert response['success']
assert response['result'] == {
'yo': 'hello'
}
async def test_lovelace_from_storage_save_before_load(hass, hass_ws_client,
hass_storage):
"""Test we can load lovelace config from storage."""
assert await async_setup_component(hass, 'lovelace', {})
client = await hass_ws_client(hass)
# Store new config
await client.send_json({
'id': 6,
'type': 'lovelace/config/save',
'config': {
'yo': 'hello'
}
})
response = await client.receive_json()
assert response['success']
assert hass_storage[lovelace.STORAGE_KEY]['data'] == {
'config': {'yo': 'hello'}
}
async def test_lovelace_from_yaml(hass, hass_ws_client):
"""Test we load lovelace config from yaml."""
assert await async_setup_component(hass, 'lovelace', {
'lovelace': {
'mode': 'YAML'
}
})
assert hass.data[frontend.DATA_PANELS]['lovelace'].config == {
'mode': 'yaml'
}
client = await hass_ws_client(hass)
# Fetch data
await client.send_json({
'id': 5,
'type': 'lovelace/config'
})
response = await client.receive_json()
assert not response['success']
assert response['error']['code'] == 'config_not_found'
# Store new config not allowed
await client.send_json({
'id': 6,
'type': 'lovelace/config/save',
'config': {
'yo': 'hello'
}
})
response = await client.receive_json()
assert not response['success']
# Patch data
with patch('homeassistant.components.lovelace.load_yaml', return_value={
'hello': 'yo'
}):
await client.send_json({
'id': 7,
'type': 'lovelace/config'
})
response = await client.receive_json()
assert response['success']
assert response['result'] == {'hello': 'yo'}
async def test_system_health_info_autogen(hass):
"""Test system health info endpoint."""
assert await async_setup_component(hass, 'lovelace', {})
info = await get_system_health_info(hass, 'lovelace')
assert info == {'mode': 'auto-gen'}
async def test_system_health_info_storage(hass, hass_storage):
"""Test system health info endpoint."""
hass_storage[lovelace.STORAGE_KEY] = {
'key': 'lovelace',
'version': 1,
'data': {
'config': {
'resources': [],
'views': []
}
}
}
assert await async_setup_component(hass, 'lovelace', {})
info = await get_system_health_info(hass, 'lovelace')
assert info == {
'mode': 'storage',
'resources': 0,
'views': 0,
}
async def test_system_health_info_yaml(hass):
"""Test system health info endpoint."""
assert await async_setup_component(hass, 'lovelace', {
'lovelace': {
'mode': 'YAML'
}
})
with patch('homeassistant.components.lovelace.load_yaml', return_value={
'views': [
{
'cards': []
}
]
}):
info = await get_system_health_info(hass, 'lovelace')
assert info == {
'mode': 'yaml',
'resources': 0,
'views': 1,
}
async def test_system_health_info_yaml_not_found(hass):
"""Test system health info endpoint."""
assert await async_setup_component(hass, 'lovelace', {
'lovelace': {
'mode': 'YAML'
}
})
info = await get_system_health_info(hass, 'lovelace')
assert info == {
'mode': 'yaml',
'error': "{} not found".format(hass.config.path('ui-lovelace.yaml'))
}