Skip to content

Commit 59e9988

Browse files
committed
Add extra tests to Wallbox component
1 parent 75ff473 commit 59e9988

File tree

2 files changed

+182
-1
lines changed

2 files changed

+182
-1
lines changed

tests/components/wallbox/__init__.py

+100
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,56 @@
8585
},
8686
}
8787

88+
test_response_eco_mode = {
89+
CHARGER_CHARGING_POWER_KEY: 0,
90+
CHARGER_STATUS_ID_KEY: 193,
91+
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
92+
CHARGER_CHARGING_SPEED_KEY: 0,
93+
CHARGER_ADDED_RANGE_KEY: 150,
94+
CHARGER_ADDED_ENERGY_KEY: 44.697,
95+
CHARGER_NAME_KEY: "WallboxName",
96+
CHARGER_DATA_KEY: {
97+
CHARGER_MAX_CHARGING_CURRENT_KEY: 24,
98+
CHARGER_ENERGY_PRICE_KEY: 0.4,
99+
CHARGER_LOCKED_UNLOCKED_KEY: False,
100+
CHARGER_SERIAL_NUMBER_KEY: "20000",
101+
CHARGER_PART_NUMBER_KEY: "PLP1-0-2-4-9-002-E",
102+
CHARGER_SOFTWARE_KEY: {CHARGER_CURRENT_VERSION_KEY: "5.5.10"},
103+
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
104+
CHARGER_MAX_ICP_CURRENT_KEY: 20,
105+
CHARGER_PLAN_KEY: {CHARGER_FEATURES_KEY: [CHARGER_POWER_BOOST_KEY]},
106+
CHARGER_ECO_SMART_KEY: {
107+
CHARGER_ECO_SMART_STATUS_KEY: True,
108+
CHARGER_ECO_SMART_MODE_KEY: 0,
109+
},
110+
},
111+
}
112+
113+
114+
test_response_full_solar = {
115+
CHARGER_CHARGING_POWER_KEY: 0,
116+
CHARGER_STATUS_ID_KEY: 193,
117+
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
118+
CHARGER_CHARGING_SPEED_KEY: 0,
119+
CHARGER_ADDED_RANGE_KEY: 150,
120+
CHARGER_ADDED_ENERGY_KEY: 44.697,
121+
CHARGER_NAME_KEY: "WallboxName",
122+
CHARGER_DATA_KEY: {
123+
CHARGER_MAX_CHARGING_CURRENT_KEY: 24,
124+
CHARGER_ENERGY_PRICE_KEY: 0.4,
125+
CHARGER_LOCKED_UNLOCKED_KEY: False,
126+
CHARGER_SERIAL_NUMBER_KEY: "20000",
127+
CHARGER_PART_NUMBER_KEY: "PLP1-0-2-4-9-002-E",
128+
CHARGER_SOFTWARE_KEY: {CHARGER_CURRENT_VERSION_KEY: "5.5.10"},
129+
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
130+
CHARGER_MAX_ICP_CURRENT_KEY: 20,
131+
CHARGER_PLAN_KEY: {CHARGER_FEATURES_KEY: [CHARGER_POWER_BOOST_KEY]},
132+
CHARGER_ECO_SMART_KEY: {
133+
CHARGER_ECO_SMART_STATUS_KEY: True,
134+
CHARGER_ECO_SMART_MODE_KEY: 1,
135+
},
136+
},
137+
}
88138

89139
authorisation_response = {
90140
"data": {
@@ -139,6 +189,56 @@ async def setup_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None
139189
await hass.async_block_till_done()
140190

141191

192+
async def setup_integration_ecosmart_eco_mode(
193+
hass: HomeAssistant, entry: MockConfigEntry
194+
) -> None:
195+
"""Test wallbox sensor class setup."""
196+
with requests_mock.Mocker() as mock_request:
197+
mock_request.get(
198+
"https://user-api.wall-box.com/users/signin",
199+
json=authorisation_response,
200+
status_code=HTTPStatus.OK,
201+
)
202+
mock_request.get(
203+
"https://api.wall-box.com/chargers/status/12345",
204+
json=test_response_eco_mode,
205+
status_code=HTTPStatus.OK,
206+
)
207+
mock_request.put(
208+
"https://api.wall-box.com/v2/charger/12345",
209+
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
210+
status_code=HTTPStatus.OK,
211+
)
212+
213+
await hass.config_entries.async_setup(entry.entry_id)
214+
await hass.async_block_till_done()
215+
216+
217+
async def setup_integration_ecosmart_full_solar(
218+
hass: HomeAssistant, entry: MockConfigEntry
219+
) -> None:
220+
"""Test wallbox sensor class setup."""
221+
with requests_mock.Mocker() as mock_request:
222+
mock_request.get(
223+
"https://user-api.wall-box.com/users/signin",
224+
json=authorisation_response,
225+
status_code=HTTPStatus.OK,
226+
)
227+
mock_request.get(
228+
"https://api.wall-box.com/chargers/status/12345",
229+
json=test_response_full_solar,
230+
status_code=HTTPStatus.OK,
231+
)
232+
mock_request.put(
233+
"https://api.wall-box.com/v2/charger/12345",
234+
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
235+
status_code=HTTPStatus.OK,
236+
)
237+
238+
await hass.config_entries.async_setup(entry.entry_id)
239+
await hass.async_block_till_done()
240+
241+
142242
async def setup_integration_bidir(hass: HomeAssistant, entry: MockConfigEntry) -> None:
143243
"""Test wallbox sensor class setup."""
144244
with requests_mock.Mocker() as mock_request:

tests/components/wallbox/test_select.py

+82-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
from homeassistant.core import HomeAssistant
1414
from homeassistant.exceptions import ConfigEntryAuthFailed
1515

16-
from . import authorisation_response, setup_integration
16+
from . import (
17+
authorisation_response,
18+
setup_integration,
19+
setup_integration_ecosmart_eco_mode,
20+
setup_integration_ecosmart_full_solar,
21+
)
1722
from .const import MOCK_SELECT_ENTITY_ID
1823

1924
from tests.common import MockConfigEntry
@@ -62,6 +67,82 @@ async def test_wallbox_select_class(
6267
blocking=True,
6368
)
6469

70+
71+
async def test_wallbox_select_ecosmart_eco_mode_class(
72+
hass: HomeAssistant, entry: MockConfigEntry
73+
) -> None:
74+
"""Test wallbox select eco mode."""
75+
await setup_integration_ecosmart_eco_mode(hass, entry)
76+
77+
state = hass.states.get(MOCK_SELECT_ENTITY_ID)
78+
assert state
79+
assert state.state == EcoSmartMode.ECO_MODE
80+
81+
with requests_mock.Mocker() as mock_request:
82+
mock_request.get(
83+
"https://user-api.wall-box.com/users/signin",
84+
json=authorisation_response,
85+
status_code=200,
86+
)
87+
mock_request.put(
88+
"https://api.wall-box.com/v4/chargers/12345/eco-smart",
89+
json={CHARGER_STATUS_ID_KEY: 193},
90+
status_code=200,
91+
)
92+
93+
await hass.services.async_call(
94+
SELECT_DOMAIN,
95+
SERVICE_SELECT_OPTION,
96+
{
97+
ATTR_ENTITY_ID: MOCK_SELECT_ENTITY_ID,
98+
ATTR_OPTION: EcoSmartMode.FULL_SOLAR,
99+
},
100+
blocking=True,
101+
)
102+
103+
await hass.services.async_call(
104+
SELECT_DOMAIN,
105+
SERVICE_SELECT_OPTION,
106+
{
107+
ATTR_ENTITY_ID: MOCK_SELECT_ENTITY_ID,
108+
ATTR_OPTION: EcoSmartMode.OFF,
109+
},
110+
blocking=True,
111+
)
112+
113+
114+
async def test_wallbox_select_ecosmart_full_solar_class(
115+
hass: HomeAssistant, entry: MockConfigEntry
116+
) -> None:
117+
"""Test wallbox select eco mode."""
118+
await setup_integration_ecosmart_full_solar(hass, entry)
119+
120+
state = hass.states.get(MOCK_SELECT_ENTITY_ID)
121+
assert state
122+
assert state.state == EcoSmartMode.FULL_SOLAR
123+
124+
with requests_mock.Mocker() as mock_request:
125+
mock_request.get(
126+
"https://user-api.wall-box.com/users/signin",
127+
json=authorisation_response,
128+
status_code=200,
129+
)
130+
mock_request.put(
131+
"https://api.wall-box.com/v4/chargers/12345/eco-smart",
132+
json={CHARGER_STATUS_ID_KEY: 193},
133+
status_code=200,
134+
)
135+
136+
await hass.services.async_call(
137+
SELECT_DOMAIN,
138+
SERVICE_SELECT_OPTION,
139+
{
140+
ATTR_ENTITY_ID: MOCK_SELECT_ENTITY_ID,
141+
ATTR_OPTION: EcoSmartMode.ECO_MODE,
142+
},
143+
blocking=True,
144+
)
145+
65146
await hass.services.async_call(
66147
SELECT_DOMAIN,
67148
SERVICE_SELECT_OPTION,

0 commit comments

Comments
 (0)