1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-12 06:50:00 +00:00
Files
.devcontainer
.github
.vscode
docs
homeassistant
script
tests
auth
components
abode
adguard
air_quality
airly
alarm_control_panel
alert
alexa
almond
ambiclimate
ambient_station
androidtv
api
api_streams
apns
apprise
aprs
arcam_fmj
arlo
asuswrt
aurora
auth
automatic
automation
awair
aws
axis
bayesian
binary_sensor
blackbird
bom
broadlink
buienradar
caldav
calendar
camera
canary
cast
cert_expiry
climate
cloud
coinmarketcap
command_line
config
configurator
conversation
coolmaster
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
geonetnz_quakes
glances
google
google_assistant
google_domains
google_pubsub
google_translate
google_wifi
gpslogger
graphite
group
hangouts
hassio
hddtemp
heos
here_travel_time
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
iaqualink
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
izone
jewish_calendar
kira
light
linky
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
minio
mobile_app
mochad
modbus
mold_indicator
monoprice
moon
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mythicbeastsdns
namecheapdns
neato
ness_alarm
nest
nextbus
no_ip
notify
notion
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nws
nx584
onboarding
openalpr_cloud
openalpr_local
openhardwaremonitor
opentherm_gw
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pi_hole
pilight
plant
plex
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
__init__.py
common.py
conftest.py
test_binary_sensor.py
test_init.py
test_light.py
test_sensor.py
test_switch.py
rmvtransport
rss_feed_template
samsungtv
scene
script
season
sensor
seventeentrack
shell_command
shopping_list
sigfox
simplisafe
simulated
sleepiq
sma
smartthings
smhi
smtp
snips
solaredge
solarlog
soma
somfy
sonarr
sonos
soundtouch
spaceapi
spc
splunk
sql
ssdp
startca
statistics
statsd
stream
stt
sun
switch
switcher_kis
system_health
system_log
tcp
teksavvy
tellduslive
template
threshold
time_date
timer
tod
tomato
toon
tplink
traccar
tradfri
transmission
transport_nsw
trend
tts
twentemilieu
twilio
uk_transport
unifi
unifi_direct
universal
updater
upnp
uptime
usgs_earthquakes_feed
utility_meter
uvc
vacuum
velbus
verisure
version
vesync
voicerss
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
withings
wled
workday
worldclock
wsdot
wunderground
wwlln
xiaomi
xiaomi_miio
yamaha
yandex_transport
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
.codecov.yml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.pre-commit-config-all.yaml
.pre-commit-config.yaml
.readthedocs.yml
.travis.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
azure-pipelines-ci.yml
azure-pipelines-release.yml
azure-pipelines-translation.yml
azure-pipelines-wheels.yml
pylintrc
pyproject.toml
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
setup.py
tox.ini
core/tests/components/ring/test_sensor.py
Paulus Schoutsen 4de97abc3a Black
2019-07-31 12:25:30 -07:00

116 lines
4.4 KiB
Python

"""The tests for the Ring sensor platform."""
import os
import unittest
import requests_mock
import homeassistant.components.ring.sensor as ring
from homeassistant.components import ring as base_ring
from homeassistant.helpers.icon import icon_for_battery_level
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":
expected_icon = icon_for_battery_level(
battery_level=int(device.state), charging=False
)
assert device.icon == expected_icon
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"]
assert not device.should_poll