mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 06:20:01 +00:00
.devcontainer
.github
.vscode
docs
homeassistant
machine
pylint
rootfs
script
tests
auth
backports
components
abode
accuweather
acmeda
adax
adguard
advantage_air
aemet
agent_dvr
air_quality
airly
airnow
airthings
airtouch4
airvisual
airzone
alarm_control_panel
alarmdecoder
alert
alexa
almond
ambee
amberelectric
ambiclimate
ambient_station
analytics
androidtv
apache_kafka
api
api_streams
apple_tv
apprise
aprs
arcam_fmj
arlo
aseko_pool_live
asuswrt
atag
august
aurora
aurora_abb_powerone
aussie_broadband
auth
automation
awair
aws
axis
azure_devops
azure_event_hub
backup
balboa
bayesian
binary_sensor
blackbird
blebox
blink
blueprint
bluetooth_le_tracker
bmw_connected_drive
bond
bosch_shc
braviatv
broadlink
brother
brunt
bsblan
buienradar
button
caldav
calendar
camera
canary
cast
cert_expiry
climacell
climate
cloud
cloudflare
co2signal
coinbase
color_extractor
comfoconnect
command_line
compensation
config
configurator
control4
conversation
coolmaster
coronavirus
counter
cover
cpuspeed
crownstone
daikin
darksky
datadog
debugpy
deconz
default_config
demo
denonavr
derivative
device_automation
device_sun_light_trigger
device_tracker
devolo_home_control
devolo_home_network
dexcom
dhcp
diagnostics
dialogflow
directv
discovery
dlna_dmr
dlna_dms
dnsip
doorbird
dsmr
dte_energy_bridge
duckdns
dunehd
dynalite
eafm
ecobee
econet
efergy
elgato
elkm1
elmax
emonitor
emulated_hue
emulated_kasa
emulated_roku
energy
enocean
enphase_envoy
environment_canada
epson
esphome
everlights
evil_genius_labs
ezviz
faa_delays
facebook
facebox
fail2ban
fan
feedreader
ffmpeg
fido
file
filesize
filter
fireservicerota
firmata
fivem
fjaraskupan
flic
flick_electric
flipr
flo
flume
flunearyou
flux
flux_led
folder
folder_watcher
foobot
forecast_solar
forked_daapd
foscam
freebox
freedns
freedompro
fritz
fritzbox
fritzbox_callmonitor
fronius
frontend
garages_amsterdam
gdacs
generic
generic_hygrostat
generic_thermostat
geo_json_events
geo_location
geo_rss_events
geofency
geonetnz_quakes
geonetnz_volcano
gios
github
glances
goalzero
gogogate2
goodwe
google
google_assistant
google_domains
google_pubsub
google_translate
google_travel_time
google_wifi
gpslogger
graphite
gree
greeneye_monitor
group
growatt_server
guardian
habitica
hangouts
harmony
hassio
hddtemp
heos
here_travel_time
hisense_aehw4a1
history
history_stats
hive
hlk_sw16
home_connect
home_plus_control
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
homewizard
honeywell
html5
http
huawei_lte
hue
huisbaasje
humidifier
hunterdouglas_powerview
hvv_departures
hyperion
ialarm
iaqualink
icloud
ifttt
ign_sismologia
image
image_processing
imap_email_content
influxdb
input_boolean
input_button
input_datetime
input_number
input_select
input_text
insteon
integration
intellifire
intent
intent_script
ios
iotawatt
ipma
ipp
iqvia
islamic_prayer_times
iss
isy994
izone
jellyfin
jewish_calendar
juicenet
kaleidescape
keenetic_ndms2
kira
kmtronic
knx
kodi
konnected
kostal_plenticore
kraken
kulersky
lastfm
launch_library
lcn
light
litejet
litterrobot
local_file
local_ip
locative
lock
logbook
logentries
logger
logi_circle
london_air
lookin
lovelace
luftdaten
lutron_caseta
lyric
mailbox
mailgun
manual
manual_mqtt
marytts
maxcube
mazda
media_player
media_source
melcloud
melissa
meraki
met
met_eireann
meteo_france
meteoclimatic
metoffice
mfi
microsoft_face
microsoft_face_detect
microsoft_face_identify
mikrotik
mill
min_max
minecraft_server
minio
mjpeg
mobile_app
mochad
modbus
modem_callerid
modern_forms
moehlenhoff_alpha2
mold_indicator
monoprice
moon
motion_blinds
motioneye
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mullvad
mutesync
my
myq
mysensors
mythicbeastsdns
nam
namecheapdns
nanoleaf
neato
ness_alarm
nest
netatmo
netgear
network
nexia
nextbus
nfandroidtv
nightscout
nina
nmap_tracker
no_ip
notify
notify_events
notion
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nuki
numato
number
nut
nws
nx584
nzbget
octoprint
omnilogic
onboarding
oncue
ondilo_ico
onewire
onvif
open_meteo
openalpr_cloud
openalpr_local
openerz
opengarage
openhardwaremonitor
opentherm_gw
openuv
openweathermap
opnsense
overkiz
ovo_energy
owntracks
p1_monitor
panasonic_viera
panel_custom
panel_iframe
persistent_notification
person
philips_js
pi_hole
picnic
pilight
ping
plaato
plant
plex
plugwise
plum_lightpad
point
poolsense
powerwall
profiler
progettihwsw
prometheus
prosegur
proximity
ps4
pure_energie
push
pushbullet
pvoutput
pvpc_hourly_pricing
python_script
qld_bushfire
qwikswitch
rachio
radarr
radio_browser
rainforest_eagle
rainmachine
random
rdw
recollect_waste
recorder
reddit
remember_the_milk
remote
renault
rest
rest_command
rflink
rfxtrx
ridwell
ring
risco
rituals_perfume_genie
rmvtransport
roku
roomba
roon
rpi_power
rss_feed_template
rtsp_to_webrtc
ruckus_unleashed
safe_mode
samsungtv
scene
scrape
screenlogic
script
search
season
select
sense
senseme
sensibo
sensor
sentry
seventeentrack
sharkiq
shell_command
shelly
shopping_list
sia
sigfox
sighthound
signal_messenger
simplisafe
simulated
siren
slack
sleepiq
sma
smappee
smart_meter_texas
smartthings
smarttub
smhi
smtp
snips
solaredge
solarlog
solax
soma
somfy
somfy_mylink
sonarr
songpal
sonos
soundtouch
spaceapi
spc
speedtestdotnet
spider
spotify
sql
squeezebox
srp_energy
ssdp
starline
startca
statistics
statsd
steamist
stookalert
stream
stt
subaru
sun
surepetcare
switch
switch_as_x
switchbot
switcher_kis
syncthing
syncthru
synology_dsm
system_bridge
system_health
system_log
tado
tag
tailscale
tasmota
tcp
telegram
tellduslive
template
tesla_wall_connector
threshold
tibber
tile
time_date
timer
tod
todoist
tolo
tomato
tomorrowio
toon
totalconnect
tplink
traccar
trace
tractive
tradfri
trafikverket_weatherstation
transmission
transport_nsw
trend
tts
tuya
twentemilieu
twilio
twinkly
twitch
uk_transport
unifi
unifi_direct
unifiprotect
universal
upb
upcloud
updater
upnp
uptime
uptimerobot
usb
usgs_earthquakes_feed
utility_meter
uvc
vacuum
vallox
velbus
venstar
vera
verisure
version
vesync
vicare
vilfo
vizio
vlc_telnet
voicerss
volumio
vultr
wake_on_lan
wallbox
water_heater
watttime
waze_travel_time
weather
webhook
webostv
websocket_api
wemo
whirlpool
whois
wiffi
wilight
withings
wiz
wled
wolflink
workday
worldclock
wsdot
xbox
xiaomi
xiaomi_aqara
xiaomi_miio
yale_smart_alarm
yamaha
yamaha_musiccast
yandex_transport
yandextts
yeelight
youless
zeroconf
zerproc
zha
zodiac
zone
zwave_js
fixtures
__init__.py
common.py
conftest.py
test_api.py
test_binary_sensor.py
test_button.py
test_climate.py
test_config_flow.py
test_config_validation.py
test_cover.py
test_device_action.py
test_device_condition.py
test_device_trigger.py
test_diagnostics.py
test_discovery.py
test_events.py
test_fan.py
test_humidifier.py
test_init.py
test_light.py
test_lock.py
test_migrate.py
test_number.py
test_select.py
test_sensor.py
test_services.py
test_siren.py
test_switch.py
test_trigger.py
zwave_me
__init__.py
conftest.py
fixtures
hassfest
helpers
pylint
resources
scripts
test_util
testing_config
util
__init__.py
bandit.yaml
common.py
conftest.py
ignore_uncaught_exceptions.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_exceptions.py
test_loader.py
test_main.py
test_requirements.py
test_runner.py
test_setup.py
test_test_fixtures.py
.core_files.yaml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hadolint.yaml
.ignore
.pre-commit-config.yaml
.prettierignore
.readthedocs.yml
.strict-typing
.yamllint
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
build.yaml
codecov.yml
mypy.ini
pyproject.toml
requirements.txt
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
setup.cfg
tox.ini

* Use new enums in zwave_js tests * Convert == to is * Refactor some ATTR_ * as well. * Address review comments
307 lines
8.8 KiB
Python
307 lines
8.8 KiB
Python
"""Test the Z-Wave JS number platform."""
|
|
from unittest.mock import MagicMock
|
|
|
|
from zwave_js_server.event import Event
|
|
from zwave_js_server.model.node import Node
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import STATE_UNKNOWN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity import EntityCategory
|
|
import homeassistant.helpers.entity_registry as er
|
|
|
|
DEFAULT_TONE_SELECT_ENTITY = "select.indoor_siren_6_default_tone_2"
|
|
PROTECTION_SELECT_ENTITY = "select.family_room_combo_local_protection_state"
|
|
MULTILEVEL_SWITCH_SELECT_ENTITY = "select.front_door_siren"
|
|
|
|
|
|
async def test_default_tone_select(
|
|
hass: HomeAssistant,
|
|
client: MagicMock,
|
|
aeotec_zw164_siren: Node,
|
|
integration: ConfigEntry,
|
|
) -> None:
|
|
"""Test the default tone select entity."""
|
|
node = aeotec_zw164_siren
|
|
state = hass.states.get(DEFAULT_TONE_SELECT_ENTITY)
|
|
|
|
assert state
|
|
assert state.state == "17ALAR~1 (35 sec)"
|
|
attr = state.attributes
|
|
assert attr["options"] == [
|
|
"01DING~1 (5 sec)",
|
|
"02DING~1 (9 sec)",
|
|
"03TRAD~1 (11 sec)",
|
|
"04ELEC~1 (2 sec)",
|
|
"05WEST~1 (13 sec)",
|
|
"06CHIM~1 (7 sec)",
|
|
"07CUCK~1 (31 sec)",
|
|
"08TRAD~1 (6 sec)",
|
|
"09SMOK~1 (11 sec)",
|
|
"10SMOK~1 (6 sec)",
|
|
"11FIRE~1 (35 sec)",
|
|
"12COSE~1 (5 sec)",
|
|
"13KLAX~1 (38 sec)",
|
|
"14DEEP~1 (41 sec)",
|
|
"15WARN~1 (37 sec)",
|
|
"16TORN~1 (46 sec)",
|
|
"17ALAR~1 (35 sec)",
|
|
"18DEEP~1 (62 sec)",
|
|
"19ALAR~1 (15 sec)",
|
|
"20ALAR~1 (7 sec)",
|
|
"21DIGI~1 (8 sec)",
|
|
"22ALER~1 (64 sec)",
|
|
"23SHIP~1 (4 sec)",
|
|
"25CHRI~1 (4 sec)",
|
|
"26GONG~1 (12 sec)",
|
|
"27SING~1 (1 sec)",
|
|
"28TONA~1 (5 sec)",
|
|
"29UPWA~1 (2 sec)",
|
|
"30DOOR~1 (27 sec)",
|
|
]
|
|
|
|
entity_registry = er.async_get(hass)
|
|
entity_entry = entity_registry.async_get(DEFAULT_TONE_SELECT_ENTITY)
|
|
|
|
assert entity_entry
|
|
assert entity_entry.entity_category is EntityCategory.CONFIG
|
|
|
|
# Test select option with string value
|
|
await hass.services.async_call(
|
|
"select",
|
|
"select_option",
|
|
{"entity_id": DEFAULT_TONE_SELECT_ENTITY, "option": "30DOOR~1 (27 sec)"},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(client.async_send_command.call_args_list) == 1
|
|
args = client.async_send_command.call_args[0][0]
|
|
assert args["command"] == "node.set_value"
|
|
assert args["nodeId"] == node.node_id
|
|
assert args["valueId"] == {
|
|
"endpoint": 2,
|
|
"commandClass": 121,
|
|
"commandClassName": "Sound Switch",
|
|
"property": "defaultToneId",
|
|
"propertyName": "defaultToneId",
|
|
"ccVersion": 1,
|
|
"metadata": {
|
|
"type": "number",
|
|
"readable": True,
|
|
"writeable": True,
|
|
"label": "Default tone ID",
|
|
"min": 0,
|
|
"max": 254,
|
|
},
|
|
"value": 17,
|
|
}
|
|
assert args["value"] == 30
|
|
|
|
client.async_send_command.reset_mock()
|
|
|
|
# Test value update from value updated event
|
|
event = Event(
|
|
type="value updated",
|
|
data={
|
|
"source": "node",
|
|
"event": "value updated",
|
|
"nodeId": node.node_id,
|
|
"args": {
|
|
"commandClassName": "Sound Switch",
|
|
"commandClass": 121,
|
|
"endpoint": 2,
|
|
"property": "defaultToneId",
|
|
"newValue": 30,
|
|
"prevValue": 17,
|
|
"propertyName": "defaultToneId",
|
|
},
|
|
},
|
|
)
|
|
node.receive_event(event)
|
|
|
|
state = hass.states.get(DEFAULT_TONE_SELECT_ENTITY)
|
|
assert state
|
|
assert state.state == "30DOOR~1 (27 sec)"
|
|
|
|
|
|
async def test_protection_select(
|
|
hass: HomeAssistant,
|
|
client: MagicMock,
|
|
inovelli_lzw36: Node,
|
|
integration: ConfigEntry,
|
|
) -> None:
|
|
"""Test the default tone select entity."""
|
|
node = inovelli_lzw36
|
|
state = hass.states.get(PROTECTION_SELECT_ENTITY)
|
|
|
|
assert state
|
|
assert state.state == "Unprotected"
|
|
attr = state.attributes
|
|
assert attr["options"] == [
|
|
"Unprotected",
|
|
"ProtectedBySequence",
|
|
"NoOperationPossible",
|
|
]
|
|
|
|
entity_registry = er.async_get(hass)
|
|
entity_entry = entity_registry.async_get(PROTECTION_SELECT_ENTITY)
|
|
|
|
assert entity_entry
|
|
assert entity_entry.entity_category is EntityCategory.CONFIG
|
|
|
|
# Test select option with string value
|
|
await hass.services.async_call(
|
|
"select",
|
|
"select_option",
|
|
{"entity_id": PROTECTION_SELECT_ENTITY, "option": "ProtectedBySequence"},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(client.async_send_command.call_args_list) == 1
|
|
args = client.async_send_command.call_args[0][0]
|
|
assert args["command"] == "node.set_value"
|
|
assert args["nodeId"] == node.node_id
|
|
assert args["valueId"] == {
|
|
"endpoint": 0,
|
|
"commandClass": 117,
|
|
"commandClassName": "Protection",
|
|
"property": "local",
|
|
"propertyName": "local",
|
|
"ccVersion": 2,
|
|
"metadata": {
|
|
"type": "number",
|
|
"readable": True,
|
|
"writeable": True,
|
|
"label": "Local protection state",
|
|
"states": {
|
|
"0": "Unprotected",
|
|
"1": "ProtectedBySequence",
|
|
"2": "NoOperationPossible",
|
|
},
|
|
},
|
|
"value": 0,
|
|
}
|
|
assert args["value"] == 1
|
|
|
|
client.async_send_command.reset_mock()
|
|
|
|
# Test value update from value updated event
|
|
event = Event(
|
|
type="value updated",
|
|
data={
|
|
"source": "node",
|
|
"event": "value updated",
|
|
"nodeId": node.node_id,
|
|
"args": {
|
|
"commandClassName": "Protection",
|
|
"commandClass": 117,
|
|
"endpoint": 0,
|
|
"property": "local",
|
|
"newValue": 1,
|
|
"prevValue": 0,
|
|
"propertyName": "local",
|
|
},
|
|
},
|
|
)
|
|
node.receive_event(event)
|
|
|
|
state = hass.states.get(PROTECTION_SELECT_ENTITY)
|
|
assert state
|
|
assert state.state == "ProtectedBySequence"
|
|
|
|
# Test null value
|
|
event = Event(
|
|
type="value updated",
|
|
data={
|
|
"source": "node",
|
|
"event": "value updated",
|
|
"nodeId": node.node_id,
|
|
"args": {
|
|
"commandClassName": "Protection",
|
|
"commandClass": 117,
|
|
"endpoint": 0,
|
|
"property": "local",
|
|
"newValue": None,
|
|
"prevValue": 1,
|
|
"propertyName": "local",
|
|
},
|
|
},
|
|
)
|
|
node.receive_event(event)
|
|
|
|
state = hass.states.get(PROTECTION_SELECT_ENTITY)
|
|
assert state
|
|
assert state.state == STATE_UNKNOWN
|
|
|
|
|
|
async def test_multilevel_switch_select(hass, client, fortrezz_ssa1_siren, integration):
|
|
"""Test Multilevel Switch CC based select entity."""
|
|
node = fortrezz_ssa1_siren
|
|
state = hass.states.get(MULTILEVEL_SWITCH_SELECT_ENTITY)
|
|
|
|
assert state
|
|
assert state.state == "Off"
|
|
attr = state.attributes
|
|
assert attr["options"] == [
|
|
"Off",
|
|
"Strobe ONLY",
|
|
"Siren ONLY",
|
|
"Siren & Strobe FULL Alarm",
|
|
]
|
|
|
|
# Test select option with string value
|
|
await hass.services.async_call(
|
|
"select",
|
|
"select_option",
|
|
{"entity_id": MULTILEVEL_SWITCH_SELECT_ENTITY, "option": "Strobe ONLY"},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(client.async_send_command.call_args_list) == 1
|
|
args = client.async_send_command.call_args[0][0]
|
|
assert args["command"] == "node.set_value"
|
|
assert args["nodeId"] == node.node_id
|
|
assert args["valueId"] == {
|
|
"endpoint": 0,
|
|
"commandClass": 38,
|
|
"commandClassName": "Multilevel Switch",
|
|
"property": "targetValue",
|
|
"propertyName": "targetValue",
|
|
"ccVersion": 1,
|
|
"metadata": {
|
|
"type": "number",
|
|
"readable": True,
|
|
"writeable": True,
|
|
"label": "Target value",
|
|
"valueChangeOptions": ["transitionDuration"],
|
|
"min": 0,
|
|
"max": 99,
|
|
},
|
|
}
|
|
assert args["value"] == 33
|
|
|
|
client.async_send_command.reset_mock()
|
|
|
|
# Test value update from value updated event
|
|
event = Event(
|
|
type="value updated",
|
|
data={
|
|
"source": "node",
|
|
"event": "value updated",
|
|
"nodeId": node.node_id,
|
|
"args": {
|
|
"commandClassName": "Multilevel Switch",
|
|
"commandClass": 38,
|
|
"endpoint": 0,
|
|
"property": "currentValue",
|
|
"newValue": 33,
|
|
"prevValue": 0,
|
|
"propertyName": "currentValue",
|
|
},
|
|
},
|
|
)
|
|
node.receive_event(event)
|
|
|
|
state = hass.states.get(MULTILEVEL_SWITCH_SELECT_ENTITY)
|
|
assert state.state == "Strobe ONLY"
|