mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 14:29:58 +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
aladdin_connect
alarm_control_panel
alarmdecoder
alert
alexa
almond
ambee
amberelectric
ambiclimate
ambient_station
analytics
androidtv
apache_kafka
api
api_streams
apple_tv
application_credentials
apprise
aprs
arcam_fmj
aseko_pool_live
asuswrt
atag
august
aurora
aurora_abb_powerone
aussie_broadband
auth
automation
awair
aws
axis
azure_devops
azure_event_hub
backup
baf
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
deluge
demo
denonavr
derivative
device_automation
device_sun_light_trigger
device_tracker
devolo_home_control
devolo_home_network
dexcom
dhcp
diagnostics
dialogflow
directv
discord
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
fibaro
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
geocaching
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
hardkernel
hardware
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
laundrify
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
meater
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
peco
persistent_notification
person
philips_js
pi_hole
picnic
pilight
ping
plaato
plant
plex
plugwise
fixtures
__init__.py
conftest.py
test_binary_sensor.py
test_climate.py
test_config_flow.py
test_diagnostics.py
test_init.py
test_sensor.py
test_switch.py
plum_lightpad
point
poolsense
powerwall
profiler
progettihwsw
prometheus
prosegur
proximity
ps4
pure_energie
push
pushbullet
pvoutput
pvpc_hourly_pricing
python_script
qld_bushfire
qnap_qsw
qwikswitch
rachio
radarr
radio_browser
radiotherm
rainforest_eagle
rainmachine
random
raspberry_pi
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
sabnzbd
safe_mode
samsungtv
scene
scrape
screenlogic
script
search
season
select
sense
senseme
sensibo
sensor
sentry
senz
seventeentrack
sharkiq
shell_command
shelly
shopping_list
sia
sigfox
sighthound
signal_messenger
simplisafe
simulated
siren
skybell
slack
sleepiq
slimproto
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
steam_online
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
tankerkoenig
tasmota
tautulli
tcp
telegram
telegram_bot
tellduslive
template
tesla_wall_connector
threshold
tibber
tile
time_date
timer
tod
todoist
tolo
tomato
tomorrowio
toon
totalconnect
tplink
traccar
trace
tractive
tradfri
trafikverket_ferry
trafikverket_train
trafikverket_weatherstation
transmission
transport_nsw
trend
tts
tuya
twentemilieu
twilio
twinkly
twitch
uk_transport
ukraine_alarm
unifi
unifi_direct
unifiprotect
universal
upb
upcloud
update
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
vulcan
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
ws66i
wsdot
xbox
xiaomi
xiaomi_aqara
xiaomi_miio
yale_smart_alarm
yamaha
yamaha_musiccast
yandex_transport
yandextts
yeelight
yolink
youless
zeroconf
zerproc
zha
zodiac
zone
zwave_js
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
177 lines
5.3 KiB
Python
177 lines
5.3 KiB
Python
"""Setup mocks for the Plugwise integration tests."""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Generator
|
|
import json
|
|
from typing import Any
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.plugwise.const import API, DOMAIN, PW_TYPE
|
|
from homeassistant.const import (
|
|
CONF_HOST,
|
|
CONF_MAC,
|
|
CONF_PASSWORD,
|
|
CONF_PORT,
|
|
CONF_USERNAME,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
|
|
def _read_json(environment: str, call: str) -> dict[str, Any]:
|
|
"""Undecode the json data."""
|
|
fixture = load_fixture(f"plugwise/{environment}/{call}.json")
|
|
return json.loads(fixture)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config_entry() -> MockConfigEntry:
|
|
"""Return the default mocked config entry."""
|
|
return MockConfigEntry(
|
|
title="My Plugwise",
|
|
domain=DOMAIN,
|
|
data={
|
|
CONF_HOST: "127.0.0.1",
|
|
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
|
CONF_PASSWORD: "test-password",
|
|
CONF_PORT: 80,
|
|
CONF_USERNAME: "smile",
|
|
PW_TYPE: API,
|
|
},
|
|
unique_id="smile98765",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|
"""Mock setting up a config entry."""
|
|
with patch(
|
|
"homeassistant.components.plugwise.async_setup_entry", return_value=True
|
|
) as mock_setup:
|
|
yield mock_setup
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_smile_config_flow() -> Generator[None, MagicMock, None]:
|
|
"""Return a mocked Smile client."""
|
|
with patch(
|
|
"homeassistant.components.plugwise.config_flow.Smile",
|
|
autospec=True,
|
|
) as smile_mock:
|
|
smile = smile_mock.return_value
|
|
smile.smile_hostname = "smile12345"
|
|
smile.smile_name = "Test Smile Name"
|
|
smile.connect.return_value = True
|
|
yield smile
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_smile_adam() -> Generator[None, MagicMock, None]:
|
|
"""Create a Mock Adam environment for testing exceptions."""
|
|
chosen_env = "adam_multiple_devices_per_zone"
|
|
|
|
with patch(
|
|
"homeassistant.components.plugwise.gateway.Smile", autospec=True
|
|
) as smile_mock:
|
|
smile = smile_mock.return_value
|
|
|
|
smile.gateway_id = "fe799307f1624099878210aa0b9f1475"
|
|
smile.heater_id = "90986d591dcd426cae3ec3e8111ff730"
|
|
smile.smile_version = "3.0.15"
|
|
smile.smile_type = "thermostat"
|
|
smile.smile_hostname = "smile98765"
|
|
smile.smile_name = "Adam"
|
|
|
|
smile.connect.return_value = True
|
|
|
|
smile.notifications = _read_json(chosen_env, "notifications")
|
|
smile.async_update.return_value = _read_json(chosen_env, "all_data")
|
|
|
|
yield smile
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_smile_anna() -> Generator[None, MagicMock, None]:
|
|
"""Create a Mock Anna environment for testing exceptions."""
|
|
chosen_env = "anna_heatpump"
|
|
with patch(
|
|
"homeassistant.components.plugwise.gateway.Smile", autospec=True
|
|
) as smile_mock:
|
|
smile = smile_mock.return_value
|
|
|
|
smile.gateway_id = "015ae9ea3f964e668e490fa39da3870b"
|
|
smile.heater_id = "1cbf783bb11e4a7c8a6843dee3a86927"
|
|
smile.smile_version = "4.0.15"
|
|
smile.smile_type = "thermostat"
|
|
smile.smile_hostname = "smile98765"
|
|
smile.smile_name = "Anna"
|
|
|
|
smile.connect.return_value = True
|
|
|
|
smile.notifications = _read_json(chosen_env, "notifications")
|
|
smile.async_update.return_value = _read_json(chosen_env, "all_data")
|
|
|
|
yield smile
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_smile_p1() -> Generator[None, MagicMock, None]:
|
|
"""Create a Mock P1 DSMR environment for testing exceptions."""
|
|
chosen_env = "p1v3_full_option"
|
|
with patch(
|
|
"homeassistant.components.plugwise.gateway.Smile", autospec=True
|
|
) as smile_mock:
|
|
smile = smile_mock.return_value
|
|
|
|
smile.gateway_id = "e950c7d5e1ee407a858e2a8b5016c8b3"
|
|
smile.heater_id = None
|
|
smile.smile_version = "3.3.9"
|
|
smile.smile_type = "power"
|
|
smile.smile_hostname = "smile98765"
|
|
smile.smile_name = "Smile P1"
|
|
|
|
smile.connect.return_value = True
|
|
|
|
smile.notifications = _read_json(chosen_env, "notifications")
|
|
smile.async_update.return_value = _read_json(chosen_env, "all_data")
|
|
|
|
yield smile
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_stretch() -> Generator[None, MagicMock, None]:
|
|
"""Create a Mock Stretch environment for testing exceptions."""
|
|
chosen_env = "stretch_v31"
|
|
with patch(
|
|
"homeassistant.components.plugwise.gateway.Smile", autospec=True
|
|
) as smile_mock:
|
|
smile = smile_mock.return_value
|
|
|
|
smile.gateway_id = "259882df3c05415b99c2d962534ce820"
|
|
smile.heater_id = None
|
|
smile.smile_version = "3.1.11"
|
|
smile.smile_type = "stretch"
|
|
smile.smile_hostname = "stretch98765"
|
|
smile.smile_name = "Stretch"
|
|
|
|
smile.connect.return_value = True
|
|
smile.async_update.return_value = _read_json(chosen_env, "all_data")
|
|
|
|
yield smile
|
|
|
|
|
|
@pytest.fixture
|
|
async def init_integration(
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
|
) -> MockConfigEntry:
|
|
"""Set up the Plugwise integration for testing."""
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
return mock_config_entry
|