mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 15:30:03 +00:00
.github
docs
homeassistant
script
tests
auth
components
air_quality
alarm_control_panel
alexa
ambient_station
auth
automation
binary_sensor
calendar
camera
cast
climate
cloud
config
counter
cover
daikin
deconz
device_tracker
dialogflow
emulated_hue
emulated_roku
esphome
fan
frontend
geo_location
geofency
google_assistant
gpslogger
group
hangouts
hassio
homekit
homekit_controller
homematicip_cloud
http
hue
ifttt
image_processing
ios
light
__init__.py
common.py
test_demo.py
test_everlights.py
test_group.py
test_init.py
test_litejet.py
test_mochad.py
test_rflink.py
test_rfxtrx.py
test_switch.py
test_template.py
test_tradfri.py
test_zwave.py
locative
lock
lovelace
luftdaten
mailbox
mailgun
media_player
mqtt
nest
notify
onboarding
openuv
owntracks
persistent_notification
point
rainmachine
recorder
remote
scene
sensor
simplisafe
smartthings
smhi
sonos
switch
system_health
tellduslive
timer
tradfri
tts
twilio
unifi
upnp
utility_meter
vacuum
water_heater
weather
websocket_api
zha
zone
zwave
__init__.py
conftest.py
test_alert.py
test_api.py
test_canary.py
test_configurator.py
test_conversation.py
test_datadog.py
test_demo.py
test_device_sun_light_trigger.py
test_discovery.py
test_duckdns.py
test_dyson.py
test_feedreader.py
test_ffmpeg.py
test_folder_watcher.py
test_freedns.py
test_google.py
test_google_domains.py
test_graphite.py
test_history.py
test_history_graph.py
test_huawei_lte.py
test_influxdb.py
test_init.py
test_input_boolean.py
test_input_datetime.py
test_input_number.py
test_input_select.py
test_input_text.py
test_intent_script.py
test_introduction.py
test_kira.py
test_litejet.py
test_logbook.py
test_logentries.py
test_logger.py
test_melissa.py
test_microsoft_face.py
test_mqtt_eventstream.py
test_mqtt_statestream.py
test_mythicbeastsdns.py
test_namecheapdns.py
test_ness_alarm.py
test_no_ip.py
test_nuheat.py
test_panel_custom.py
test_panel_iframe.py
test_pilight.py
test_plant.py
test_prometheus.py
test_proximity.py
test_python_script.py
test_qwikswitch.py
test_remember_the_milk.py
test_rest_command.py
test_rflink.py
test_rfxtrx.py
test_ring.py
test_rss_feed_template.py
test_script.py
test_shell_command.py
test_shopping_list.py
test_sleepiq.py
test_snips.py
test_spaceapi.py
test_spc.py
test_splunk.py
test_statsd.py
test_sun.py
test_system_log.py
test_updater.py
test_vultr.py
test_wake_on_lan.py
test_webhook.py
test_weblink.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

* Update switch * Update script * Update light * Fix tests * Fix config/script hook * Async_create_task * Fix flux switch
80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
"""The tests for the demo light component."""
|
|
import pytest
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
from homeassistant.components import light
|
|
|
|
from tests.components.light import common
|
|
|
|
ENTITY_LIGHT = 'light.bed_light'
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def setup_comp(hass):
|
|
"""Set up demo component."""
|
|
hass.loop.run_until_complete(async_setup_component(hass, light.DOMAIN, {
|
|
'light': {
|
|
'platform': 'demo',
|
|
}}))
|
|
|
|
|
|
async def test_state_attributes(hass):
|
|
"""Test light state attributes."""
|
|
common.async_turn_on(
|
|
hass, ENTITY_LIGHT, xy_color=(.4, .4), brightness=25)
|
|
await hass.async_block_till_done()
|
|
state = hass.states.get(ENTITY_LIGHT)
|
|
assert light.is_on(hass, ENTITY_LIGHT)
|
|
assert (0.4, 0.4) == state.attributes.get(light.ATTR_XY_COLOR)
|
|
assert 25 == state.attributes.get(light.ATTR_BRIGHTNESS)
|
|
assert (255, 234, 164) == state.attributes.get(light.ATTR_RGB_COLOR)
|
|
assert 'rainbow' == state.attributes.get(light.ATTR_EFFECT)
|
|
common.async_turn_on(
|
|
hass, ENTITY_LIGHT, rgb_color=(251, 253, 255),
|
|
white_value=254)
|
|
await hass.async_block_till_done()
|
|
state = hass.states.get(ENTITY_LIGHT)
|
|
assert 254 == state.attributes.get(light.ATTR_WHITE_VALUE)
|
|
assert (250, 252, 255) == state.attributes.get(light.ATTR_RGB_COLOR)
|
|
assert (0.319, 0.326) == state.attributes.get(light.ATTR_XY_COLOR)
|
|
common.async_turn_on(hass, ENTITY_LIGHT, color_temp=400, effect='none')
|
|
await hass.async_block_till_done()
|
|
state = hass.states.get(ENTITY_LIGHT)
|
|
assert 400 == state.attributes.get(light.ATTR_COLOR_TEMP)
|
|
assert 153 == state.attributes.get(light.ATTR_MIN_MIREDS)
|
|
assert 500 == state.attributes.get(light.ATTR_MAX_MIREDS)
|
|
assert 'none' == state.attributes.get(light.ATTR_EFFECT)
|
|
common.async_turn_on(hass, ENTITY_LIGHT, kelvin=3000, brightness_pct=50)
|
|
await hass.async_block_till_done()
|
|
state = hass.states.get(ENTITY_LIGHT)
|
|
assert 333 == state.attributes.get(light.ATTR_COLOR_TEMP)
|
|
assert 127 == state.attributes.get(light.ATTR_BRIGHTNESS)
|
|
|
|
|
|
async def test_turn_off(hass):
|
|
"""Test light turn off method."""
|
|
await hass.services.async_call('light', 'turn_on', {
|
|
'entity_id': ENTITY_LIGHT
|
|
}, blocking=True)
|
|
|
|
assert light.is_on(hass, ENTITY_LIGHT)
|
|
|
|
await hass.services.async_call('light', 'turn_off', {
|
|
'entity_id': ENTITY_LIGHT
|
|
}, blocking=True)
|
|
|
|
assert not light.is_on(hass, ENTITY_LIGHT)
|
|
|
|
|
|
async def test_turn_off_without_entity_id(hass):
|
|
"""Test light turn off all lights."""
|
|
await hass.services.async_call('light', 'turn_on', {
|
|
}, blocking=True)
|
|
|
|
assert light.is_on(hass, ENTITY_LIGHT)
|
|
|
|
await hass.services.async_call('light', 'turn_off', {
|
|
}, blocking=True)
|
|
|
|
assert not light.is_on(hass, ENTITY_LIGHT)
|