|
5 | 5 |
|
6 | 6 | from PyTado.http import DeviceActivationStatus |
7 | 7 | import pytest |
| 8 | +import requests_mock |
8 | 9 |
|
9 | 10 | from homeassistant.components.tado import CONF_REFRESH_TOKEN, DOMAIN |
| 11 | +from homeassistant.core import HomeAssistant |
10 | 12 |
|
11 | | -from tests.common import MockConfigEntry, load_json_object_fixture |
| 13 | +from tests.common import MockConfigEntry, async_load_fixture, load_json_object_fixture |
12 | 14 |
|
13 | 15 |
|
14 | 16 | @pytest.fixture |
@@ -48,3 +50,196 @@ def mock_config_entry() -> MockConfigEntry: |
48 | 50 | unique_id="1", |
49 | 51 | version=2, |
50 | 52 | ) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.fixture |
| 56 | +async def init_integration(hass: HomeAssistant): |
| 57 | + """Set up the tado integration in Home Assistant.""" |
| 58 | + |
| 59 | + token_fixture = "token.json" |
| 60 | + devices_fixture = "devices.json" |
| 61 | + mobile_devices_fixture = "mobile_devices.json" |
| 62 | + me_fixture = "me.json" |
| 63 | + weather_fixture = "weather.json" |
| 64 | + home_fixture = "home.json" |
| 65 | + home_state_fixture = "home_state.json" |
| 66 | + zones_fixture = "zones.json" |
| 67 | + zone_states_fixture = "zone_states.json" |
| 68 | + |
| 69 | + # WR1 Device |
| 70 | + device_wr1_fixture = "device_wr1.json" |
| 71 | + |
| 72 | + # Smart AC with fanLevel, Vertical and Horizontal swings |
| 73 | + zone_6_state_fixture = "smartac4.with_fanlevel.json" |
| 74 | + zone_6_capabilities_fixture = "zone_with_fanlevel_horizontal_vertical_swing.json" |
| 75 | + |
| 76 | + # Smart AC with Swing |
| 77 | + zone_5_state_fixture = "smartac3.with_swing.json" |
| 78 | + zone_5_capabilities_fixture = "zone_with_swing_capabilities.json" |
| 79 | + |
| 80 | + # Water Heater 2 |
| 81 | + zone_4_state_fixture = "tadov2.water_heater.heating.json" |
| 82 | + zone_4_capabilities_fixture = "water_heater_zone_capabilities.json" |
| 83 | + |
| 84 | + # Smart AC |
| 85 | + zone_3_state_fixture = "smartac3.cool_mode.json" |
| 86 | + zone_3_capabilities_fixture = "zone_capabilities.json" |
| 87 | + |
| 88 | + # Water Heater |
| 89 | + zone_2_state_fixture = "tadov2.water_heater.auto_mode.json" |
| 90 | + zone_2_capabilities_fixture = "water_heater_zone_capabilities.json" |
| 91 | + |
| 92 | + # Tado V2 with manual heating |
| 93 | + zone_1_state_fixture = "tadov2.heating.manual_mode.json" |
| 94 | + zone_1_capabilities_fixture = "tadov2.zone_capabilities.json" |
| 95 | + |
| 96 | + # Device Temp Offset |
| 97 | + device_temp_offset = "device_temp_offset.json" |
| 98 | + |
| 99 | + # Zone Default Overlay |
| 100 | + zone_def_overlay = "zone_default_overlay.json" |
| 101 | + |
| 102 | + with requests_mock.mock() as m: |
| 103 | + m.post( |
| 104 | + "https://auth.tado.com/oauth/token", |
| 105 | + text=await async_load_fixture(hass, token_fixture, DOMAIN), |
| 106 | + ) |
| 107 | + m.get( |
| 108 | + "https://my.tado.com/api/v2/me", |
| 109 | + text=await async_load_fixture(hass, me_fixture, DOMAIN), |
| 110 | + ) |
| 111 | + m.get( |
| 112 | + "https://my.tado.com/api/v2/homes/1/", |
| 113 | + text=await async_load_fixture(hass, home_fixture, DOMAIN), |
| 114 | + ) |
| 115 | + m.get( |
| 116 | + "https://my.tado.com/api/v2/homes/1/weather", |
| 117 | + text=await async_load_fixture(hass, weather_fixture, DOMAIN), |
| 118 | + ) |
| 119 | + m.get( |
| 120 | + "https://my.tado.com/api/v2/homes/1/state", |
| 121 | + text=await async_load_fixture(hass, home_state_fixture, DOMAIN), |
| 122 | + ) |
| 123 | + m.get( |
| 124 | + "https://my.tado.com/api/v2/homes/1/devices", |
| 125 | + text=await async_load_fixture(hass, devices_fixture, DOMAIN), |
| 126 | + ) |
| 127 | + m.get( |
| 128 | + "https://my.tado.com/api/v2/homes/1/mobileDevices", |
| 129 | + text=await async_load_fixture(hass, mobile_devices_fixture, DOMAIN), |
| 130 | + ) |
| 131 | + m.get( |
| 132 | + "https://my.tado.com/api/v2/devices/WR1/", |
| 133 | + text=await async_load_fixture(hass, device_wr1_fixture, DOMAIN), |
| 134 | + ) |
| 135 | + m.get( |
| 136 | + "https://my.tado.com/api/v2/devices/WR1/temperatureOffset", |
| 137 | + text=await async_load_fixture(hass, device_temp_offset, DOMAIN), |
| 138 | + ) |
| 139 | + m.get( |
| 140 | + "https://my.tado.com/api/v2/devices/WR4/temperatureOffset", |
| 141 | + text=await async_load_fixture(hass, device_temp_offset, DOMAIN), |
| 142 | + ) |
| 143 | + m.get( |
| 144 | + "https://my.tado.com/api/v2/homes/1/zones", |
| 145 | + text=await async_load_fixture(hass, zones_fixture, DOMAIN), |
| 146 | + ) |
| 147 | + m.get( |
| 148 | + "https://my.tado.com/api/v2/homes/1/zoneStates", |
| 149 | + text=await async_load_fixture(hass, zone_states_fixture, DOMAIN), |
| 150 | + ) |
| 151 | + m.get( |
| 152 | + "https://my.tado.com/api/v2/homes/1/zones/6/capabilities", |
| 153 | + text=await async_load_fixture(hass, zone_6_capabilities_fixture, DOMAIN), |
| 154 | + ) |
| 155 | + m.get( |
| 156 | + "https://my.tado.com/api/v2/homes/1/zones/5/capabilities", |
| 157 | + text=await async_load_fixture(hass, zone_5_capabilities_fixture, DOMAIN), |
| 158 | + ) |
| 159 | + m.get( |
| 160 | + "https://my.tado.com/api/v2/homes/1/zones/4/capabilities", |
| 161 | + text=await async_load_fixture(hass, zone_4_capabilities_fixture, DOMAIN), |
| 162 | + ) |
| 163 | + m.get( |
| 164 | + "https://my.tado.com/api/v2/homes/1/zones/3/capabilities", |
| 165 | + text=await async_load_fixture(hass, zone_3_capabilities_fixture, DOMAIN), |
| 166 | + ) |
| 167 | + m.get( |
| 168 | + "https://my.tado.com/api/v2/homes/1/zones/2/capabilities", |
| 169 | + text=await async_load_fixture(hass, zone_2_capabilities_fixture, DOMAIN), |
| 170 | + ) |
| 171 | + m.get( |
| 172 | + "https://my.tado.com/api/v2/homes/1/zones/1/capabilities", |
| 173 | + text=await async_load_fixture(hass, zone_1_capabilities_fixture, DOMAIN), |
| 174 | + ) |
| 175 | + m.get( |
| 176 | + "https://my.tado.com/api/v2/homes/1/zones/1/defaultOverlay", |
| 177 | + text=await async_load_fixture(hass, zone_def_overlay, DOMAIN), |
| 178 | + ) |
| 179 | + m.get( |
| 180 | + "https://my.tado.com/api/v2/homes/1/zones/2/defaultOverlay", |
| 181 | + text=await async_load_fixture(hass, zone_def_overlay, DOMAIN), |
| 182 | + ) |
| 183 | + m.get( |
| 184 | + "https://my.tado.com/api/v2/homes/1/zones/3/defaultOverlay", |
| 185 | + text=await async_load_fixture(hass, zone_def_overlay, DOMAIN), |
| 186 | + ) |
| 187 | + m.get( |
| 188 | + "https://my.tado.com/api/v2/homes/1/zones/4/defaultOverlay", |
| 189 | + text=await async_load_fixture(hass, zone_def_overlay, DOMAIN), |
| 190 | + ) |
| 191 | + m.get( |
| 192 | + "https://my.tado.com/api/v2/homes/1/zones/5/defaultOverlay", |
| 193 | + text=await async_load_fixture(hass, zone_def_overlay, DOMAIN), |
| 194 | + ) |
| 195 | + m.get( |
| 196 | + "https://my.tado.com/api/v2/homes/1/zones/6/defaultOverlay", |
| 197 | + text=await async_load_fixture(hass, zone_def_overlay, DOMAIN), |
| 198 | + ) |
| 199 | + m.get( |
| 200 | + "https://my.tado.com/api/v2/homes/1/zones/6/state", |
| 201 | + text=await async_load_fixture(hass, zone_6_state_fixture, DOMAIN), |
| 202 | + ) |
| 203 | + m.get( |
| 204 | + "https://my.tado.com/api/v2/homes/1/zones/5/state", |
| 205 | + text=await async_load_fixture(hass, zone_5_state_fixture, DOMAIN), |
| 206 | + ) |
| 207 | + m.get( |
| 208 | + "https://my.tado.com/api/v2/homes/1/zones/4/state", |
| 209 | + text=await async_load_fixture(hass, zone_4_state_fixture, DOMAIN), |
| 210 | + ) |
| 211 | + m.get( |
| 212 | + "https://my.tado.com/api/v2/homes/1/zones/3/state", |
| 213 | + text=await async_load_fixture(hass, zone_3_state_fixture, DOMAIN), |
| 214 | + ) |
| 215 | + m.get( |
| 216 | + "https://my.tado.com/api/v2/homes/1/zones/2/state", |
| 217 | + text=await async_load_fixture(hass, zone_2_state_fixture, DOMAIN), |
| 218 | + ) |
| 219 | + m.get( |
| 220 | + "https://my.tado.com/api/v2/homes/1/zones/1/state", |
| 221 | + text=await async_load_fixture(hass, zone_1_state_fixture, DOMAIN), |
| 222 | + ) |
| 223 | + m.post( |
| 224 | + "https://login.tado.com/oauth2/token", |
| 225 | + text=await async_load_fixture(hass, token_fixture, DOMAIN), |
| 226 | + ) |
| 227 | + entry = MockConfigEntry( |
| 228 | + domain=DOMAIN, |
| 229 | + version=2, |
| 230 | + data={ |
| 231 | + CONF_REFRESH_TOKEN: "mock-token", |
| 232 | + }, |
| 233 | + options={"fallback": "NEXT_TIME_BLOCK"}, |
| 234 | + ) |
| 235 | + entry.add_to_hass(hass) |
| 236 | + |
| 237 | + await hass.config_entries.async_setup(entry.entry_id) |
| 238 | + await hass.async_block_till_done() |
| 239 | + |
| 240 | + # For a first refresh |
| 241 | + await entry.runtime_data.coordinator.async_refresh() |
| 242 | + await entry.runtime_data.mobile_coordinator.async_refresh() |
| 243 | + await hass.async_block_till_done() |
| 244 | + |
| 245 | + yield |
0 commit comments