1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-13 07:20:01 +00:00
Files
.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
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
__init__.py
test_api_streams.py
test_awair.py
test_bom.py
test_canary.py
test_coinmarketcap.py
test_command_line.py
test_darksky.py
test_dsmr.py
test_dte_energy_bridge.py
test_dyson.py
test_efergy.py
test_entur_public_transport.py
test_fail2ban.py
test_fido.py
test_file.py
test_filesize.py
test_filter.py
test_folder.py
test_foobot.py
test_geo_rss_events.py
test_google_wifi.py
test_hddtemp.py
test_history_stats.py
test_hydroquebec.py
test_imap_email_content.py
test_integration.py
test_islamic_prayer_times.py
test_jewish_calendar.py
test_london_air.py
test_mfi.py
test_mhz19.py
test_min_max.py
test_moldindicator.py
test_moon.py
test_mqtt_room.py
test_nsw_fuel_station.py
test_openhardwaremonitor.py
test_pilight.py
test_radarr.py
test_random.py
test_rest.py
test_rflink.py
test_rfxtrx.py
test_ring.py
test_rmvtransport.py
test_season.py
test_sigfox.py
test_simulated.py
test_sleepiq.py
test_sonarr.py
test_sql.py
test_srp_energy.py
test_startca.py
test_statistics.py
test_tcp.py
test_teksavvy.py
test_template.py
test_time_date.py
test_transport_nsw.py
test_uk_transport.py
test_uptime.py
test_version.py
test_vultr.py
test_worldclock.py
test_wsdot.py
test_wunderground.py
test_yr.py
test_yweather.py
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
core/tests/components/sensor/test_ring.py
Paulus Schoutsen b8cc547fa3 Move components to folders ()
* Move all components into folders

* Move component tests into folders

* Fix init moving

* Move tests

* Lint

* Update coverage

* Fix service descriptions

* Update CODEOWNERS
2019-02-05 19:31:15 -08:00

112 lines
4.2 KiB
Python

"""The tests for the Ring sensor platform."""
import os
import unittest
import requests_mock
from homeassistant.components.sensor import ring
from homeassistant.components import ring as base_ring
from tests.components.ring.test_init import ATTRIBUTION, VALID_CONFIG
from tests.common import (
get_test_config_dir, get_test_home_assistant, load_fixture)
class TestRingSensorSetup(unittest.TestCase):
"""Test the Ring platform."""
DEVICES = []
def add_entities(self, devices, action):
"""Mock add devices."""
for device in devices:
self.DEVICES.append(device)
def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(self.cache):
os.remove(self.cache)
def setUp(self):
"""Initialize values for this testcase class."""
self.hass = get_test_home_assistant()
self.cache = get_test_config_dir(base_ring.DEFAULT_CACHEDB)
self.config = {
'username': 'foo',
'password': 'bar',
'monitored_conditions': [
'battery',
'last_activity',
'last_ding',
'last_motion',
'volume',
'wifi_signal_category',
'wifi_signal_strength']
}
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self.cleanup()
@requests_mock.Mocker()
def test_sensor(self, mock):
"""Test the Ring sensor class and methods."""
mock.post('https://oauth.ring.com/oauth/token',
text=load_fixture('ring_oauth.json'))
mock.post('https://api.ring.com/clients_api/session',
text=load_fixture('ring_session.json'))
mock.get('https://api.ring.com/clients_api/ring_devices',
text=load_fixture('ring_devices.json'))
mock.get('https://api.ring.com/clients_api/doorbots/987652/history',
text=load_fixture('ring_doorbots.json'))
mock.get('https://api.ring.com/clients_api/doorbots/987652/health',
text=load_fixture('ring_doorboot_health_attrs.json'))
mock.get('https://api.ring.com/clients_api/chimes/999999/health',
text=load_fixture('ring_chime_health_attrs.json'))
base_ring.setup(self.hass, VALID_CONFIG)
ring.setup_platform(self.hass,
self.config,
self.add_entities,
None)
for device in self.DEVICES:
device.update()
if device.name == 'Front Battery':
assert 80 == device.state
assert 'hp_cam_v1' == \
device.device_state_attributes['kind']
assert 'stickup_cams' == \
device.device_state_attributes['type']
if device.name == 'Front Door Battery':
assert 100 == device.state
assert 'lpd_v1' == \
device.device_state_attributes['kind']
assert 'chimes' != \
device.device_state_attributes['type']
if device.name == 'Downstairs Volume':
assert 2 == device.state
assert '1.2.3' == \
device.device_state_attributes['firmware']
assert 'ring_mock_wifi' == \
device.device_state_attributes['wifi_name']
assert 'mdi:bell-ring' == device.icon
assert 'chimes' == \
device.device_state_attributes['type']
if device.name == 'Front Door Last Activity':
assert not device.device_state_attributes['answered']
assert 'America/New_York' == \
device.device_state_attributes['timezone']
if device.name == 'Downstairs WiFi Signal Strength':
assert -39 == device.state
if device.name == 'Front Door WiFi Signal Category':
assert 'good' == device.state
if device.name == 'Front Door WiFi Signal Strength':
assert -58 == device.state
assert device.entity_picture is None
assert ATTRIBUTION == \
device.device_state_attributes['attribution']