mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 15:30:03 +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
airq
airthings
airthings_ble
airtouch4
airvisual
airzone
aladdin_connect
alarm_control_panel
alarmdecoder
alert
alexa
almond
amberelectric
ambiclimate
ambient_station
analytics
android_ip_webcam
androidtv
anthemav
apache_kafka
apcupsd
api
api_streams
apple_tv
application_credentials
apprise
aprs
aranet
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
bluemaestro
blueprint
bluetooth
bluetooth_le_tracker
bmw_connected_drive
bond
bosch_shc
braviatv
broadlink
brother
brunt
bsblan
bthome
buienradar
button
caldav
calendar
camera
canary
cast
cert_expiry
clicksend_tts
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
dsmr_reader
dte_energy_bridge
duckdns
dunehd
dynalite
eafm
ecobee
econet
ecowitt
efergy
eight_sleep
elgato
elkm1
elmax
emonitor
emulated_hue
emulated_kasa
emulated_roku
energy
enocean
enphase_envoy
environment_canada
epson
escea
esphome
everlights
evil_genius_labs
ezviz
faa_delays
facebook
facebox
fail2ban
fan
feedreader
ffmpeg
fibaro
fido
file
file_upload
filesize
filter
fireservicerota
firmata
fivem
fjaraskupan
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
fully_kiosk
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_assistant_sdk
google_domains
google_pubsub
google_sheets
google_translate
google_travel_time
google_wifi
govee_ble
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
hlk_sw16
home_connect
home_plus_control
homeassistant
homeassistant_alerts
homeassistant_hardware
homeassistant_sky_connect
homeassistant_yellow
homekit
homekit_controller
homematic
homematicip_cloud
homewizard
honeywell
html5
http
huawei_lte
hue
huisbaasje
humidifier
hunterdouglas_powerview
hvv_departures
hyperion
ialarm
iaqualink
ibeacon
icloud
ifttt
ign_sismologia
image
image_processing
imap_email_content
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
islamic_prayer_times
iss
isy994
izone
jellyfin
jewish_calendar
juicenet
justnimbus
kaleidescape
keenetic_ndms2
kegtron
keymitt_ble
kira
kmtronic
knx
kodi
konnected
kostal_plenticore
kraken
kulersky
lacrosse_view
lametric
landisgyr_heat_meter
lastfm
launch_library
laundrify
lcn
led_ble
lg_soundbar
lidarr
life360
lifx
light
litejet
litterrobot
livisi
local_calendar
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
matter
maxcube
mazda
meater
media_player
media_source
melcloud
melissa
melnor
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
moat
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
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
octoprint
omnilogic
onboarding
oncue
ondilo_ico
onewire
onvif
open_meteo
openalpr_cloud
openerz
openexchangerates
opengarage
openhardwaremonitor
opentherm_gw
openuv
openweathermap
opnsense
oralb
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
plum_lightpad
point
poolsense
powerwall
profiler
progettihwsw
prometheus
prosegur
proximity
prusalink
ps4
pure_energie
push
pushbullet
pushover
pvoutput
pvpc_hourly_pricing
python_script
qingping
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
repairs
rest
rest_command
rflink
rfxtrx
rhasspy
ridwell
ring
risco
rituals_perfume_genie
rmvtransport
roku
roomba
roon
rpi_power
rss_feed_template
rtsp_to_webrtc
ruckus_unleashed
ruuvitag_ble
sabnzbd
safe_mode
samsungtv
scene
schedule
scrape
screenlogic
script
search
season
select
sense
senseme
sensibo
sensirion_ble
sensor
sensorpro
sensorpush
sentry
senz
seventeentrack
sharkiq
shell_command
shelly
bluetooth
__init__.py
conftest.py
test_binary_sensor.py
test_button.py
test_climate.py
test_config_flow.py
test_coordinator.py
test_cover.py
test_device_trigger.py
test_diagnostics.py
test_init.py
test_light.py
test_logbook.py
test_number.py
test_sensor.py
test_switch.py
test_update.py
test_utils.py
shopping_list
sia
sigfox
sighthound
signal_messenger
simplepush
simplisafe
simulated
siren
skybell
slack
sleepiq
slimproto
sma
smappee
smart_meter_texas
smartthings
smarttub
smhi
smtp
snips
snmp
snooz
solaredge
solarlog
solax
soma
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
switchbee
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
text
thermobeacon
thermopro
threshold
tibber
tile
tilt_ble
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
volvooncall
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_ble
xiaomi_miio
yale_smart_alarm
yalexs_ble
yamaha
yamaha_musiccast
yandex_transport
yandextts
yeelight
yolink
youless
zamg
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
.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

* Set last_target_temp value according the unit system * Convert restored temperature values * Add test * Improve comments * Move _last_target_temp value to constants
423 lines
14 KiB
Python
423 lines
14 KiB
Python
"""Tests for Shelly climate platform."""
|
|
from unittest.mock import AsyncMock, PropertyMock
|
|
|
|
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
|
import pytest
|
|
|
|
from homeassistant.components.climate import (
|
|
ATTR_HVAC_MODE,
|
|
ATTR_PRESET_MODE,
|
|
ATTR_TARGET_TEMP_HIGH,
|
|
ATTR_TARGET_TEMP_LOW,
|
|
DOMAIN as CLIMATE_DOMAIN,
|
|
PRESET_NONE,
|
|
SERVICE_SET_HVAC_MODE,
|
|
SERVICE_SET_PRESET_MODE,
|
|
SERVICE_SET_TEMPERATURE,
|
|
HVACMode,
|
|
)
|
|
from homeassistant.components.shelly.const import DOMAIN
|
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNAVAILABLE
|
|
from homeassistant.core import State
|
|
from homeassistant.exceptions import HomeAssistantError
|
|
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
|
|
|
from . import init_integration, register_device, register_entity
|
|
|
|
from tests.common import mock_restore_cache
|
|
|
|
SENSOR_BLOCK_ID = 3
|
|
DEVICE_BLOCK_ID = 4
|
|
ENTITY_ID = f"{CLIMATE_DOMAIN}.test_name"
|
|
|
|
|
|
async def test_climate_hvac_mode(hass, mock_block_device, monkeypatch):
|
|
"""Test climate hvac mode service."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
await init_integration(hass, 1, sleep_period=1000)
|
|
|
|
# Make device online
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
# Test initial hvac mode - off
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.state == HVACMode.OFF
|
|
|
|
# Test set hvac mode heat
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
|
blocking=True,
|
|
)
|
|
mock_block_device.http_request.assert_called_once_with(
|
|
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": 20.0}
|
|
)
|
|
|
|
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 20.0)
|
|
mock_block_device.mock_update()
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.state == HVACMode.HEAT
|
|
|
|
# Test set hvac mode off
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.OFF},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_block_device.http_request.assert_called_with(
|
|
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": "4"}
|
|
)
|
|
|
|
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 4.0)
|
|
mock_block_device.mock_update()
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.state == HVACMode.OFF
|
|
|
|
# Test unavailable on error
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 1)
|
|
mock_block_device.mock_update()
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.state == STATE_UNAVAILABLE
|
|
|
|
|
|
async def test_climate_set_temperature(hass, mock_block_device, monkeypatch):
|
|
"""Test climate set temperature service."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
await init_integration(hass, 1, sleep_period=1000)
|
|
|
|
# Make device online
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.state == HVACMode.OFF
|
|
assert state.attributes[ATTR_TEMPERATURE] == 4
|
|
|
|
# Test set temperature without target temperature
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{
|
|
ATTR_ENTITY_ID: ENTITY_ID,
|
|
ATTR_TARGET_TEMP_LOW: 20,
|
|
ATTR_TARGET_TEMP_HIGH: 30,
|
|
},
|
|
blocking=True,
|
|
)
|
|
mock_block_device.http_request.assert_not_called()
|
|
|
|
# Test set temperature
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_TEMPERATURE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 23},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_block_device.http_request.assert_called_once_with(
|
|
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": "23.0"}
|
|
)
|
|
|
|
|
|
async def test_climate_set_preset_mode(hass, mock_block_device, monkeypatch):
|
|
"""Test climate set preset mode service."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "mode", None)
|
|
await init_integration(hass, 1, sleep_period=1000)
|
|
|
|
# Make device online
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE
|
|
|
|
# Test set Profile2
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_PRESET_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: "Profile2"},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_block_device.http_request.assert_called_once_with(
|
|
"get", "thermostat/0", {"schedule": 1, "schedule_profile": "2"}
|
|
)
|
|
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "mode", 2)
|
|
mock_block_device.mock_update()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.attributes[ATTR_PRESET_MODE] == "Profile2"
|
|
|
|
# Set preset to none
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_PRESET_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_NONE},
|
|
blocking=True,
|
|
)
|
|
|
|
assert len(mock_block_device.http_request.mock_calls) == 2
|
|
mock_block_device.http_request.assert_called_with(
|
|
"get", "thermostat/0", {"schedule": 0}
|
|
)
|
|
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "mode", 0)
|
|
mock_block_device.mock_update()
|
|
|
|
state = hass.states.get(ENTITY_ID)
|
|
assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE
|
|
|
|
|
|
async def test_block_restored_climate(hass, mock_block_device, device_reg, monkeypatch):
|
|
"""Test block restored climate."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
|
register_device(device_reg, entry)
|
|
entity_id = register_entity(
|
|
hass,
|
|
CLIMATE_DOMAIN,
|
|
"test_name",
|
|
"sensor_0",
|
|
entry,
|
|
)
|
|
mock_restore_cache(hass, [State(entity_id, HVACMode.HEAT)])
|
|
|
|
monkeypatch.setattr(mock_block_device, "initialized", False)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
|
|
|
# Partial update, should not change state
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
|
|
|
# Make device online
|
|
monkeypatch.setattr(mock_block_device, "initialized", True)
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.OFF
|
|
|
|
|
|
async def test_block_restored_climate_us_customery(
|
|
hass, mock_block_device, device_reg, monkeypatch
|
|
):
|
|
"""Test block restored climate with US CUSTOMATY unit system."""
|
|
hass.config.units = US_CUSTOMARY_SYSTEM
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
|
register_device(device_reg, entry)
|
|
entity_id = register_entity(
|
|
hass,
|
|
CLIMATE_DOMAIN,
|
|
"test_name",
|
|
"sensor_0",
|
|
entry,
|
|
)
|
|
attrs = {"current_temperature": 67, "temperature": 68}
|
|
mock_restore_cache(hass, [State(entity_id, HVACMode.HEAT, attributes=attrs)])
|
|
|
|
monkeypatch.setattr(mock_block_device, "initialized", False)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
|
assert hass.states.get(entity_id).attributes.get("temperature") == 68
|
|
assert hass.states.get(entity_id).attributes.get("current_temperature") == 67
|
|
|
|
# Partial update, should not change state
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
|
assert hass.states.get(entity_id).attributes.get("temperature") == 68
|
|
assert hass.states.get(entity_id).attributes.get("current_temperature") == 67
|
|
|
|
# Make device online
|
|
monkeypatch.setattr(mock_block_device, "initialized", True)
|
|
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 19.7)
|
|
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "temp", 18.2)
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
|
assert hass.states.get(entity_id).attributes.get("temperature") == 67
|
|
assert hass.states.get(entity_id).attributes.get("current_temperature") == 65
|
|
|
|
|
|
async def test_block_restored_climate_unavailable(
|
|
hass, mock_block_device, device_reg, monkeypatch
|
|
):
|
|
"""Test block restored climate unavailable state."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
|
register_device(device_reg, entry)
|
|
entity_id = register_entity(
|
|
hass,
|
|
CLIMATE_DOMAIN,
|
|
"test_name",
|
|
"sensor_0",
|
|
entry,
|
|
)
|
|
mock_restore_cache(hass, [State(entity_id, STATE_UNAVAILABLE)])
|
|
|
|
monkeypatch.setattr(mock_block_device, "initialized", False)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.OFF
|
|
|
|
|
|
async def test_block_restored_climate_set_preset_before_online(
|
|
hass, mock_block_device, device_reg, monkeypatch
|
|
):
|
|
"""Test block restored climate set preset before device is online."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
|
register_device(device_reg, entry)
|
|
entity_id = register_entity(
|
|
hass,
|
|
CLIMATE_DOMAIN,
|
|
"test_name",
|
|
"sensor_0",
|
|
entry,
|
|
)
|
|
mock_restore_cache(hass, [State(entity_id, HVACMode.HEAT)])
|
|
|
|
monkeypatch.setattr(mock_block_device, "initialized", False)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_PRESET_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: "Profile1"},
|
|
blocking=True,
|
|
)
|
|
|
|
mock_block_device.http_request.assert_not_called()
|
|
|
|
|
|
async def test_block_set_mode_connection_error(hass, mock_block_device, monkeypatch):
|
|
"""Test block device set mode connection error."""
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
monkeypatch.setattr(
|
|
mock_block_device,
|
|
"http_request",
|
|
AsyncMock(side_effect=DeviceConnectionError),
|
|
)
|
|
await init_integration(hass, 1, sleep_period=1000)
|
|
|
|
# Make device online
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
with pytest.raises(HomeAssistantError):
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
|
blocking=True,
|
|
)
|
|
|
|
|
|
async def test_block_set_mode_auth_error(hass, mock_block_device, monkeypatch):
|
|
"""Test block device set mode authentication error."""
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
monkeypatch.setattr(
|
|
mock_block_device,
|
|
"http_request",
|
|
AsyncMock(side_effect=InvalidAuthError),
|
|
)
|
|
entry = await init_integration(hass, 1, sleep_period=1000)
|
|
|
|
# Make device online
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
await hass.services.async_call(
|
|
CLIMATE_DOMAIN,
|
|
SERVICE_SET_HVAC_MODE,
|
|
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
|
blocking=True,
|
|
)
|
|
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
flows = hass.config_entries.flow.async_progress()
|
|
assert len(flows) == 1
|
|
|
|
flow = flows[0]
|
|
assert flow.get("step_id") == "reauth_confirm"
|
|
assert flow.get("handler") == DOMAIN
|
|
|
|
assert "context" in flow
|
|
assert flow["context"].get("source") == SOURCE_REAUTH
|
|
assert flow["context"].get("entry_id") == entry.entry_id
|
|
|
|
|
|
async def test_block_restored_climate_auth_error(
|
|
hass, mock_block_device, device_reg, monkeypatch
|
|
):
|
|
"""Test block restored climate with authentication error during init."""
|
|
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
|
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
|
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
|
register_device(device_reg, entry)
|
|
entity_id = register_entity(
|
|
hass,
|
|
CLIMATE_DOMAIN,
|
|
"test_name",
|
|
"sensor_0",
|
|
entry,
|
|
)
|
|
mock_restore_cache(hass, [State(entity_id, HVACMode.HEAT)])
|
|
|
|
monkeypatch.setattr(mock_block_device, "initialized", False)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
# Make device online with auth error
|
|
monkeypatch.setattr(mock_block_device, "initialized", True)
|
|
type(mock_block_device).settings = PropertyMock(
|
|
return_value={}, side_effect=InvalidAuthError
|
|
)
|
|
mock_block_device.mock_update()
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
flows = hass.config_entries.flow.async_progress()
|
|
assert len(flows) == 1
|
|
|
|
flow = flows[0]
|
|
assert flow.get("step_id") == "reauth_confirm"
|
|
assert flow.get("handler") == DOMAIN
|
|
|
|
assert "context" in flow
|
|
assert flow["context"].get("source") == SOURCE_REAUTH
|
|
assert flow["context"].get("entry_id") == entry.entry_id
|