mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 14:29:58 +00:00
.github
docs
homeassistant
script
tests
auth
components
air_quality
alarm_control_panel
alert
alexa
ambient_station
api
arlo
auth
automation
binary_sensor
calendar
camera
canary
cast
climate
cloud
config
configurator
conversation
counter
cover
daikin
datadog
deconz
default_config
demo
device_sun_light_trigger
device_tracker
dialogflow
discovery
duckdns
dyson
ecobee
emulated_hue
__init__.py
test_hue_api.py
test_init.py
test_upnp.py
emulated_roku
esphome
fan
feedreader
ffmpeg
folder_watcher
freedns
fritzbox
frontend
geo_location
geofency
google
google_assistant
google_domains
google_pubsub
gpslogger
graphite
group
hangouts
hassio
history
history_graph
homekit
homekit_controller
homematicip_cloud
http
huawei_lte
hue
ifttt
image_processing
influxdb
init
input_boolean
input_datetime
input_number
input_select
input_text
intent_script
introduction
ios
ipma
kira
light
litejet
locative
lock
logbook
logentries
logger
lovelace
luftdaten
mailbox
mailgun
media_player
melissa
microsoft_face
mochad
mqtt
mqtt_eventstream
mqtt_statestream
mythicbeastsdns
namecheapdns
ness_alarm
nest
no_ip
notify
nuheat
onboarding
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pilight
plant
point
prometheus
proximity
ps4
python_script
qwikswitch
rainmachine
recorder
remember_the_milk
remote
rest_command
rflink
rfxtrx
ring
rss_feed_template
scene
script
sensor
shell_command
shopping_list
simplisafe
sleepiq
smartthings
smhi
snips
sonos
spaceapi
spc
splunk
statsd
sun
switch
system_health
system_log
tellduslive
timer
toon
tplink
tradfri
tts
twilio
unifi
updater
upnp
utility_meter
vacuum
verisure
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
xiaomi_miio
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

Reworked tests/components/emulated_hue/test_init.py to not be dependent on the specific internal implementation of util/jsonn.py
125 lines
4.1 KiB
Python
125 lines
4.1 KiB
Python
"""Test the Emulated Hue component."""
|
|
from unittest.mock import patch, Mock, MagicMock
|
|
|
|
from homeassistant.components.emulated_hue import Config
|
|
|
|
|
|
def test_config_google_home_entity_id_to_number():
|
|
"""Test config adheres to the type."""
|
|
mock_hass = Mock()
|
|
mock_hass.config.path = MagicMock("path", return_value="test_path")
|
|
conf = Config(mock_hass, {
|
|
'type': 'google_home'
|
|
})
|
|
|
|
with patch('homeassistant.components.emulated_hue.load_json',
|
|
return_value={'1': 'light.test2'}) as json_loader:
|
|
with patch('homeassistant.components.emulated_hue'
|
|
'.save_json') as json_saver:
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == '2'
|
|
|
|
assert json_saver.mock_calls[0][1][1] == {
|
|
'1': 'light.test2', '2': 'light.test'
|
|
}
|
|
|
|
assert json_saver.call_count == 1
|
|
assert json_loader.call_count == 1
|
|
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == '2'
|
|
assert json_saver.call_count == 1
|
|
|
|
number = conf.entity_id_to_number('light.test2')
|
|
assert number == '1'
|
|
assert json_saver.call_count == 1
|
|
|
|
entity_id = conf.number_to_entity_id('1')
|
|
assert entity_id == 'light.test2'
|
|
|
|
|
|
def test_config_google_home_entity_id_to_number_altered():
|
|
"""Test config adheres to the type."""
|
|
mock_hass = Mock()
|
|
mock_hass.config.path = MagicMock("path", return_value="test_path")
|
|
conf = Config(mock_hass, {
|
|
'type': 'google_home'
|
|
})
|
|
|
|
with patch('homeassistant.components.emulated_hue.load_json',
|
|
return_value={'21': 'light.test2'}) as json_loader:
|
|
with patch('homeassistant.components.emulated_hue'
|
|
'.save_json') as json_saver:
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == '22'
|
|
assert json_saver.call_count == 1
|
|
assert json_loader.call_count == 1
|
|
|
|
assert json_saver.mock_calls[0][1][1] == {
|
|
'21': 'light.test2',
|
|
'22': 'light.test',
|
|
}
|
|
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == '22'
|
|
assert json_saver.call_count == 1
|
|
|
|
number = conf.entity_id_to_number('light.test2')
|
|
assert number == '21'
|
|
assert json_saver.call_count == 1
|
|
|
|
entity_id = conf.number_to_entity_id('21')
|
|
assert entity_id == 'light.test2'
|
|
|
|
|
|
def test_config_google_home_entity_id_to_number_empty():
|
|
"""Test config adheres to the type."""
|
|
mock_hass = Mock()
|
|
mock_hass.config.path = MagicMock("path", return_value="test_path")
|
|
conf = Config(mock_hass, {
|
|
'type': 'google_home'
|
|
})
|
|
|
|
with patch('homeassistant.components.emulated_hue.load_json',
|
|
return_value={}) as json_loader:
|
|
with patch('homeassistant.components.emulated_hue'
|
|
'.save_json') as json_saver:
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == '1'
|
|
assert json_saver.call_count == 1
|
|
assert json_loader.call_count == 1
|
|
|
|
assert json_saver.mock_calls[0][1][1] == {
|
|
'1': 'light.test',
|
|
}
|
|
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == '1'
|
|
assert json_saver.call_count == 1
|
|
|
|
number = conf.entity_id_to_number('light.test2')
|
|
assert number == '2'
|
|
assert json_saver.call_count == 2
|
|
|
|
entity_id = conf.number_to_entity_id('2')
|
|
assert entity_id == 'light.test2'
|
|
|
|
|
|
def test_config_alexa_entity_id_to_number():
|
|
"""Test config adheres to the type."""
|
|
conf = Config(None, {
|
|
'type': 'alexa'
|
|
})
|
|
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == 'light.test'
|
|
|
|
number = conf.entity_id_to_number('light.test')
|
|
assert number == 'light.test'
|
|
|
|
number = conf.entity_id_to_number('light.test2')
|
|
assert number == 'light.test2'
|
|
|
|
entity_id = conf.number_to_entity_id('light.test')
|
|
assert entity_id == 'light.test'
|