mirror of
https://github.com/home-assistant/core.git
synced 2025-09-02 09:01:05 +00:00
.devcontainer
.github
.vscode
homeassistant
machine
pylint
rootfs
script
tests
auth
components
abode
accuweather
acmeda
adax
adguard
advantage_air
aemet
aftership
agent_dvr
air_quality
airgradient
airly
airnow
airq
airthings
airthings_ble
airtouch4
airtouch5
airvisual
airvisual_pro
airzone
airzone_cloud
aladdin_connect
alarm_control_panel
alarmdecoder
alert
alexa
amberelectric
ambient_network
ambient_station
analytics
analytics_insights
android_ip_webcam
androidtv
androidtv_remote
anova
anthemav
aosmith
apache_kafka
apcupsd
api
api_streams
apple_tv
application_credentials
apprise
aprilaire
aprs
apsystems
aranet
arcam_fmj
arve
aseko_pool_live
assist_pipeline
asterisk_mbox
asuswrt
atag
august
aurora
aurora_abb_powerone
aussie_broadband
auth
automation
awair
aws
axis
azure_data_explorer
azure_devops
azure_event_hub
backup
baf
balboa
bang_olufsen
bayesian
binary_sensor
blackbird
blebox
blink
blue_current
bluemaestro
blueprint
bluetooth
bluetooth_adapters
bluetooth_le_tracker
bmw_connected_drive
bond
bosch_shc
braviatv
bring
broadlink
brother
brottsplatskartan
brunt
bsblan
bthome
buienradar
button
caldav
calendar
camera
canary
cast
ccm15
cert_expiry
clicksend_tts
climate
cloud
cloudflare
co2signal
coinbase
color_extractor
comelit
comfoconnect
command_line
compensation
config
configurator
control4
conversation
coolmaster
counter
cover
cpuspeed
crownstone
daikin
datadog
date
datetime
debugpy
deconz
default_config
deluge
demo
denonavr
derivative
devialet
device_automation
device_sun_light_trigger
device_tracker
devolo_home_control
devolo_home_network
dexcom
dhcp
diagnostics
dialogflow
directv
discord
discovergy
dlink
dlna_dmr
dlna_dms
dnsip
doorbird
dormakaba_dkey
downloader
dremel_3d_printer
drop_connect
dsmr
dsmr_reader
dte_energy_bridge
duckdns
dunehd
duotecno
dwd_weather_warnings
dynalite
eafm
easyenergy
ecobee
ecoforest
econet
ecovacs
ecowitt
edl21
efergy
eight_sleep
electrasmart
electric_kiwi
elgato
elkm1
elmax
elvia
emonitor
emulated_hue
emulated_kasa
emulated_roku
energenie_power_sockets
energy
energyzero
enigma2
enocean
enphase_envoy
environment_canada
epic_games_store
epion
epson
eq3btsmart
escea
esphome
eufylife_ble
event
everlights
evil_genius_labs
ezviz
faa_delays
facebook
fail2ban
fan
fastdotcom
feedreader
ffmpeg
fibaro
fido
file
file_upload
filesize
filter
fints
fireservicerota
firmata
fitbit
fivem
fjaraskupan
flexit_bacnet
flic
flick_electric
flipr
flo
flume
flux
flux_led
folder
folder_watcher
foobot
forecast_solar
forked_daapd
foscam
freebox
freedns
freedompro
fritz
fritzbox
fritzbox_callmonitor
fronius
frontend
frontier_silicon
fully_kiosk
fyta
garages_amsterdam
gardena_bluetooth
gdacs
generic
generic_hygrostat
generic_thermostat
geo_json_events
geo_location
geo_rss_events
geocaching
geofency
geonetnz_quakes
geonetnz_volcano
gios
github
glances
goalzero
gogogate2
goodwe
google
google_assistant
google_assistant_sdk
google_domains
google_generative_ai_conversation
google_mail
google_pubsub
google_sheets
google_tasks
google_translate
google_travel_time
google_wifi
govee_ble
govee_light_local
gpsd
gpslogger
graphite
gree
greeneye_monitor
group
growatt_server
guardian
habitica
hardkernel
hardware
harmony
hassio
hddtemp
hdmi_cec
heos
here_travel_time
hisense_aehw4a1
history
history_stats
hive
hko
hlk_sw16
holiday
home_connect
homeassistant
homeassistant_alerts
homeassistant_green
homeassistant_hardware
homeassistant_sky_connect
homeassistant_yellow
homekit
homekit_controller
homematic
homematicip_cloud
homewizard
homeworks
honeywell
html5
http
huawei_lte
hue
huisbaasje
humidifier
hunterdouglas_powerview
husqvarna_automower
huum
hvv_departures
hydrawise
hyperion
ialarm
iaqualink
ibeacon
icloud
idasen_desk
ifttt
ign_sismologia
image
image_processing
image_upload
imap
imgw_pib
improv_ble
influxdb
inkbird
input_boolean
input_button
input_datetime
input_number
input_select
input_text
insteon
integration
intellifire
intent
intent_script
ios
iotawatt
ipma
ipp
iqvia
isal
islamic_prayer_times
iss
isy994
izone
jellyfin
jewish_calendar
juicenet
justnimbus
jvc_projector
kaleidescape
keenetic_ndms2
kegtron
keymitt_ble
kira
kitchen_sink
kmtronic
knx
kodi
konnected
kostal_plenticore
kraken
kulersky
lacrosse_view
lamarzocco
lametric
landisgyr_heat_meter
lastfm
launch_library
laundrify
lawn_mower
lcn
ld2410_ble
leaone
led_ble
lg_netcast
lg_soundbar
lidarr
life360
lifx
light
linear_garage_door
litejet
litterrobot
livisi
local_calendar
local_file
local_ip
local_todo
locative
lock
logbook
logentries
logger
logi_circle
london_air
london_underground
lookin
loqed
lovelace
luftdaten
lupusec
lutron
lutron_caseta
lyric
mailbox
mailgun
manual
manual_mqtt
map
marytts
matrix
matter
fixtures
__init__.py
common.py
conftest.py
test_adapter.py
test_api.py
test_binary_sensor.py
test_climate.py
test_config_flow.py
test_cover.py
test_diagnostics.py
test_door_lock.py
test_event.py
test_fan.py
test_helpers.py
test_init.py
test_light.py
test_sensor.py
test_switch.py
maxcube
mazda
meater
medcom_ble
media_extractor
media_player
media_source
melcloud
melissa
melnor
meraki
met
met_eireann
meteo_france
meteoclimatic
metoffice
mfi
microbees
microsoft
microsoft_face
microsoft_face_detect
microsoft_face_identify
mikrotik
mill
min_max
minecraft_server
minio
mjpeg
moat
mobile_app
mochad
modbus
modem_callerid
modern_forms
moehlenhoff_alpha2
mold_indicator
monoprice
monzo
moon
mopeka
motion_blinds
motionblinds_ble
motioneye
motionmount
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mullvad
mutesync
my
myq
mysensors
mystrom
mythicbeastsdns
myuplink
nam
namecheapdns
nanoleaf
neato
ness_alarm
nest
netatmo
netgear
netgear_lte
network
nexia
nextbus
nextcloud
nextdns
nfandroidtv
nibe_heatpump
nightscout
nina
nmap_tracker
no_ip
nobo_hub
notify
notify_events
notion
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nuki
numato
number
nut
nws
nx584
nzbget
obihai
octoprint
ollama
omnilogic
onboarding
oncue
ondilo_ico
onewire
onvif
open_meteo
openai_conversation
openalpr_cloud
openerz
openexchangerates
opengarage
openhardwaremonitor
openhome
opensky
opentherm_gw
openuv
openweathermap
opnsense
opower
oralb
osoenergy
otbr
ourgroceries
overkiz
ovo_energy
owntracks
p1_monitor
panasonic_viera
panel_custom
panel_iframe
peco
pegel_online
permobil
persistent_notification
person
philips_js
pi_hole
picnic
pilight
ping
pjlink
plaato
plant
plex
plugwise
plum_lightpad
point
poolsense
powerwall
private_ble_device
profiler
progettihwsw
prometheus
prosegur
proximity
prusalink
ps4
pure_energie
purpleair
push
pushbullet
pushover
pvoutput
pvpc_hourly_pricing
python_script
qbittorrent
qingping
qld_bushfire
qnap
qnap_qsw
qwikswitch
rabbitair
rachio
radarr
radio_browser
radiotherm
rainbird
rainforest_eagle
rainforest_raven
rainmachine
random
rapt_ble
raspberry_pi
rdw
recollect_waste
recorder
recovery_mode
reddit
refoss
remember_the_milk
remote
renault
renson
reolink
repairs
rest
rest_command
rflink
rfxtrx
rhasspy
ridwell
ring
risco
rituals_perfume_genie
rmvtransport
roborock
roku
romy
roomba
roon
rova
rpi_power
rss_feed_template
rtsp_to_webrtc
ruckus_unleashed
ruuvi_gateway
ruuvitag_ble
rympro
sabnzbd
samsungtv
sanix
scene
schedule
schlage
scrape
screenlogic
script
search
season
select
sense
sensibo
sensirion_ble
sensor
sensorpro
sensorpush
sentry
senz
seventeentrack
sfr_box
sharkiq
shell_command
shelly
shopping_list
sia
sigfox
sighthound
signal_messenger
simplepush
simplisafe
simulated
siren
skybell
slack
sleepiq
slimproto
sma
smappee
smart_meter_texas
smartthings
smarttub
smhi
sms
smtp
snapcast
snips
snmp
snooz
solaredge
solarlog
solax
soma
somfy_mylink
sonarr
songpal
sonos
soundtouch
spaceapi
spc
speedtestdotnet
spider
spotify
sql
squeezebox
srp_energy
ssdp
starline
starlink
startca
statistics
statsd
steam_online
steamist
stookalert
stookwijzer
stream
streamlabswater
stt
subaru
suez_water
sun
sunweg
surepetcare
swiss_public_transport
switch
switch_as_x
switchbee
switchbot
switchbot_cloud
switcher_kis
syncthing
syncthru
synology_dsm
system_bridge
system_health
system_log
systemmonitor
tado
tag
tailscale
tailwind
tami4
tankerkoenig
tasmota
tautulli
tcp
technove
tedee
telegram
telegram_bot
tellduslive
temper
template
tesla_wall_connector
teslemetry
tessie
text
thermobeacon
thermopro
thethingsnetwork
thread
threshold
tibber
tile
tilt_ble
time
time_date
timer
tod
todo
todoist
tolo
tomato
tomorrowio
toon
totalconnect
tplink
tplink_omada
traccar
traccar_server
trace
tractive
tradfri
trafikverket_camera
trafikverket_ferry
trafikverket_train
trafikverket_weatherstation
transmission
transport_nsw
trend
tts
tuya
twentemilieu
twilio
twinkly
twitch
uk_transport
ukraine_alarm
unifi
unifiprotect
universal
upb
upcloud
update
upnp
uptime
uptimerobot
usb
usgs_earthquakes_feed
utility_meter
uvc
v2c
vacuum
vallox
valve
velbus
velux
venstar
vera
verisure
version
vesync
vicare
vilfo
vizio
vlc_telnet
vodafone_station
voicerss
voip
volumio
volvooncall
vulcan
vultr
wake_on_lan
wake_word
wallbox
waqi
water_heater
watttime
waze_travel_time
weather
weatherflow
weatherflow_cloud
weatherkit
webhook
webmin
webostv
websocket_api
wemo
whirlpool
whois
wiffi
wilight
withings
wiz
wled
wolflink
workday
worldclock
ws66i
wsdot
wyoming
xbox
xiaomi
xiaomi_aqara
xiaomi_ble
xiaomi_miio
yale_smart_alarm
yalexs_ble
yamaha
yamaha_musiccast
yandex_transport
yandextts
yardian
yeelight
yolink
youless
youtube
zamg
zeroconf
zerproc
zeversolar
zha
zodiac
zone
zwave_js
zwave_me
__init__.py
conftest.py
fixtures
hassfest
helpers
non_packaged_scripts
pylint
resources
script
scripts
snapshots
test_util
testing_config
util
__init__.py
common.py
conftest.py
ignore_uncaught_exceptions.py
patch_time.py
ruff.toml
syrupy.py
test_backports.py
test_block_async_io.py
test_bootstrap.py
test_circular_imports.py
test_config.py
test_config_entries.py
test_const.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
typing.py
.core_files.yaml
.coveragerc
.dockerignore
.git-blame-ignore-revs
.gitattributes
.gitignore
.hadolint.yaml
.pre-commit-config.yaml
.prettierignore
.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_test.txt
requirements_test_all.txt
requirements_test_pre_commit.txt
245 lines
7.6 KiB
Python
245 lines
7.6 KiB
Python
"""Provide common fixtures."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from collections.abc import AsyncGenerator, Generator
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
from matter_server.client.models.node import MatterNode
|
|
from matter_server.common.const import SCHEMA_VERSION
|
|
from matter_server.common.models import ServerInfoMessage
|
|
import pytest
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .common import setup_integration_with_node_fixture
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
MOCK_FABRIC_ID = 12341234
|
|
MOCK_COMPR_FABRIC_ID = 1234
|
|
|
|
|
|
@pytest.fixture(name="matter_client")
|
|
async def matter_client_fixture() -> AsyncGenerator[MagicMock, None]:
|
|
"""Fixture for a Matter client."""
|
|
with patch(
|
|
"homeassistant.components.matter.MatterClient", autospec=True
|
|
) as client_class:
|
|
client = client_class.return_value
|
|
|
|
async def connect() -> None:
|
|
"""Mock connect."""
|
|
await asyncio.sleep(0)
|
|
|
|
async def listen(init_ready: asyncio.Event | None) -> None:
|
|
"""Mock listen."""
|
|
if init_ready is not None:
|
|
init_ready.set()
|
|
listen_block = asyncio.Event()
|
|
await listen_block.wait()
|
|
pytest.fail("Listen was not cancelled!")
|
|
|
|
client.connect = AsyncMock(side_effect=connect)
|
|
client.start_listening = AsyncMock(side_effect=listen)
|
|
client.server_info = ServerInfoMessage(
|
|
fabric_id=MOCK_FABRIC_ID,
|
|
compressed_fabric_id=MOCK_COMPR_FABRIC_ID,
|
|
schema_version=1,
|
|
sdk_version="2022.11.1",
|
|
wifi_credentials_set=True,
|
|
thread_credentials_set=True,
|
|
min_supported_schema_version=SCHEMA_VERSION,
|
|
)
|
|
|
|
yield client
|
|
|
|
|
|
@pytest.fixture(name="integration")
|
|
async def integration_fixture(
|
|
hass: HomeAssistant, matter_client: MagicMock
|
|
) -> MockConfigEntry:
|
|
"""Set up the Matter integration."""
|
|
entry = MockConfigEntry(domain="matter", data={"url": "ws://localhost:5580/ws"})
|
|
entry.add_to_hass(hass)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
return entry
|
|
|
|
|
|
@pytest.fixture(name="create_backup")
|
|
def create_backup_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock Supervisor create backup of add-on."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_create_backup"
|
|
) as create_backup:
|
|
yield create_backup
|
|
|
|
|
|
@pytest.fixture(name="addon_store_info")
|
|
def addon_store_info_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock Supervisor add-on store info."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_get_addon_store_info"
|
|
) as addon_store_info:
|
|
addon_store_info.return_value = {
|
|
"available": False,
|
|
"installed": None,
|
|
"state": None,
|
|
"version": "1.0.0",
|
|
}
|
|
yield addon_store_info
|
|
|
|
|
|
@pytest.fixture(name="addon_info")
|
|
def addon_info_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock Supervisor add-on info."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_get_addon_info",
|
|
) as addon_info:
|
|
addon_info.return_value = {
|
|
"available": False,
|
|
"hostname": None,
|
|
"options": {},
|
|
"state": None,
|
|
"update_available": False,
|
|
"version": None,
|
|
}
|
|
yield addon_info
|
|
|
|
|
|
@pytest.fixture(name="addon_not_installed")
|
|
def addon_not_installed_fixture(
|
|
addon_store_info: AsyncMock, addon_info: AsyncMock
|
|
) -> AsyncMock:
|
|
"""Mock add-on not installed."""
|
|
addon_store_info.return_value["available"] = True
|
|
return addon_info
|
|
|
|
|
|
@pytest.fixture(name="addon_installed")
|
|
def addon_installed_fixture(
|
|
addon_store_info: AsyncMock, addon_info: AsyncMock
|
|
) -> AsyncMock:
|
|
"""Mock add-on already installed but not running."""
|
|
addon_store_info.return_value = {
|
|
"available": True,
|
|
"installed": "1.0.0",
|
|
"state": "stopped",
|
|
"version": "1.0.0",
|
|
}
|
|
addon_info.return_value["available"] = True
|
|
addon_info.return_value["hostname"] = "core-matter-server"
|
|
addon_info.return_value["state"] = "stopped"
|
|
addon_info.return_value["version"] = "1.0.0"
|
|
return addon_info
|
|
|
|
|
|
@pytest.fixture(name="addon_running")
|
|
def addon_running_fixture(
|
|
addon_store_info: AsyncMock, addon_info: AsyncMock
|
|
) -> AsyncMock:
|
|
"""Mock add-on already running."""
|
|
addon_store_info.return_value = {
|
|
"available": True,
|
|
"installed": "1.0.0",
|
|
"state": "started",
|
|
"version": "1.0.0",
|
|
}
|
|
addon_info.return_value["available"] = True
|
|
addon_info.return_value["hostname"] = "core-matter-server"
|
|
addon_info.return_value["state"] = "started"
|
|
addon_info.return_value["version"] = "1.0.0"
|
|
return addon_info
|
|
|
|
|
|
@pytest.fixture(name="install_addon")
|
|
def install_addon_fixture(
|
|
addon_store_info: AsyncMock, addon_info: AsyncMock
|
|
) -> Generator[AsyncMock, None, None]:
|
|
"""Mock install add-on."""
|
|
|
|
async def install_addon_side_effect(hass: HomeAssistant, slug: str) -> None:
|
|
"""Mock install add-on."""
|
|
addon_store_info.return_value = {
|
|
"available": True,
|
|
"installed": "1.0.0",
|
|
"state": "stopped",
|
|
"version": "1.0.0",
|
|
}
|
|
addon_info.return_value["available"] = True
|
|
addon_info.return_value["state"] = "stopped"
|
|
addon_info.return_value["version"] = "1.0.0"
|
|
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_install_addon"
|
|
) as install_addon:
|
|
install_addon.side_effect = install_addon_side_effect
|
|
yield install_addon
|
|
|
|
|
|
@pytest.fixture(name="start_addon")
|
|
def start_addon_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock start add-on."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_start_addon"
|
|
) as start_addon:
|
|
yield start_addon
|
|
|
|
|
|
@pytest.fixture(name="stop_addon")
|
|
def stop_addon_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock stop add-on."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_stop_addon"
|
|
) as stop_addon:
|
|
yield stop_addon
|
|
|
|
|
|
@pytest.fixture(name="uninstall_addon")
|
|
def uninstall_addon_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock uninstall add-on."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_uninstall_addon"
|
|
) as uninstall_addon:
|
|
yield uninstall_addon
|
|
|
|
|
|
@pytest.fixture(name="update_addon")
|
|
def update_addon_fixture() -> Generator[AsyncMock, None, None]:
|
|
"""Mock update add-on."""
|
|
with patch(
|
|
"homeassistant.components.hassio.addon_manager.async_update_addon"
|
|
) as update_addon:
|
|
yield update_addon
|
|
|
|
|
|
@pytest.fixture(name="door_lock")
|
|
async def door_lock_fixture(
|
|
hass: HomeAssistant, matter_client: MagicMock
|
|
) -> MatterNode:
|
|
"""Fixture for a door lock node."""
|
|
return await setup_integration_with_node_fixture(hass, "door-lock", matter_client)
|
|
|
|
|
|
@pytest.fixture(name="door_lock_with_unbolt")
|
|
async def door_lock_with_unbolt_fixture(
|
|
hass: HomeAssistant, matter_client: MagicMock
|
|
) -> MatterNode:
|
|
"""Fixture for a door lock node with unbolt feature."""
|
|
return await setup_integration_with_node_fixture(
|
|
hass, "door-lock-with-unbolt", matter_client
|
|
)
|
|
|
|
|
|
@pytest.fixture(name="eve_contact_sensor_node")
|
|
async def eve_contact_sensor_node_fixture(
|
|
hass: HomeAssistant, matter_client: MagicMock
|
|
) -> MatterNode:
|
|
"""Fixture for a contact sensor node."""
|
|
return await setup_integration_with_node_fixture(
|
|
hass, "eve-contact-sensor", matter_client
|
|
)
|