mirror of
https://github.com/home-assistant/core.git
synced 2025-08-17 17:30:08 +00:00
.circleci
.github
docs
homeassistant
script
tests
auth
components
adguard
air_quality
alarm_control_panel
alert
alexa
ambiclimate
ambient_station
api
api_streams
apns
aprs
arlo
asuswrt
aurora
auth
automatic
automation
awair
aws
axis
bayesian
binary_sensor
blackbird
bom
broadlink
buienradar
caldav
calendar
camera
canary
cast
climate
cloud
coinmarketcap
command_line
config
configurator
conversation
counter
cover
daikin
darksky
datadog
deconz
default_config
demo
device_automation
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_translate
google_wifi
gpslogger
graphite
group
hangouts
hassio
hddtemp
heos
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
hydroquebec
ifttt
ign_sismologia
image_processing
imap_email_content
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
integration
intent_script
ios
ipma
iqvia
islamic_prayer_times
jewish_calendar
kira
light
litejet
local_file
locative
lock
logbook
logentries
logger
logi_circle
london_air
lovelace
luftdaten
mailbox
mailgun
manual
manual_mqtt
marytts
media_player
melissa
meraki
met
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
nextbus
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
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
samsungtv
scene
script
season
sensor
shell_command
shopping_list
sigfox
simplisafe
simulated
sleepiq
smartthings
smhi
smtp
snips
somfy
sonarr
sonos
soundtouch
spaceapi
spc
splunk
sql
srp_energy
ssdp
startca
statistics
statsd
stream
sun
switch
switcher_kis
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
__init__.py
test_sensor.py
wunderground
xiaomi
xiaomi_miio
yamaha
yandextts
yessssms
yr
yweather
zeroconf
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
.codecov.yml
.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
azure-pipelines-ci.yml
azure-pipelines-release.yml
azure-pipelines-wheels.yml
mypy.ini
mypyrc
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini

* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
"""The tests for the WSDOT platform."""
|
|
from datetime import datetime, timedelta, timezone
|
|
import re
|
|
import unittest
|
|
|
|
import requests_mock
|
|
from tests.common import get_test_home_assistant, load_fixture
|
|
|
|
import homeassistant.components.wsdot.sensor as wsdot
|
|
from homeassistant.components.wsdot.sensor import (
|
|
ATTR_DESCRIPTION, ATTR_TIME_UPDATED, CONF_API_KEY, CONF_ID, CONF_NAME,
|
|
CONF_TRAVEL_TIMES, RESOURCE, SCAN_INTERVAL)
|
|
from homeassistant.setup import setup_component
|
|
|
|
|
|
class TestWSDOT(unittest.TestCase):
|
|
"""Test the WSDOT platform."""
|
|
|
|
def add_entities(self, new_entities, update_before_add=False):
|
|
"""Mock add entities."""
|
|
if update_before_add:
|
|
for entity in new_entities:
|
|
entity.update()
|
|
|
|
for entity in new_entities:
|
|
self.entities.append(entity)
|
|
|
|
def setUp(self):
|
|
"""Initialize values for this testcase class."""
|
|
self.hass = get_test_home_assistant()
|
|
self.config = {
|
|
CONF_API_KEY: 'foo',
|
|
SCAN_INTERVAL: timedelta(seconds=120),
|
|
CONF_TRAVEL_TIMES: [{
|
|
CONF_ID: 96,
|
|
CONF_NAME: 'I90 EB'}],
|
|
}
|
|
self.entities = []
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
"""Stop everything that was started."""
|
|
self.hass.stop()
|
|
|
|
def test_setup_with_config(self):
|
|
"""Test the platform setup with configuration."""
|
|
assert setup_component(self.hass, 'sensor', {'wsdot': self.config})
|
|
|
|
@requests_mock.Mocker()
|
|
def test_setup(self, mock_req):
|
|
"""Test for operational WSDOT sensor with proper attributes."""
|
|
uri = re.compile(RESOURCE + '*')
|
|
mock_req.get(uri, text=load_fixture('wsdot.json'))
|
|
wsdot.setup_platform(self.hass, self.config, self.add_entities)
|
|
assert len(self.entities) == 1
|
|
sensor = self.entities[0]
|
|
assert sensor.name == 'I90 EB'
|
|
assert sensor.state == 11
|
|
assert sensor.device_state_attributes[ATTR_DESCRIPTION] == \
|
|
'Downtown Seattle to Downtown Bellevue via I-90'
|
|
assert sensor.device_state_attributes[ATTR_TIME_UPDATED] == \
|
|
datetime(2017, 1, 21, 15, 10, tzinfo=timezone(timedelta(hours=-8)))
|