Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CJNE committed Aug 19, 2024
1 parent d7cfedf commit 4d0dc20
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions custom_components/myenergi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ async def async_step_user(self, user_input=None):
scan_interval = self.config_entry.options.get(
CONF_SCAN_INTERVAL, SCAN_INTERVAL.total_seconds()
)
app_email = self.config_entry.options.get(CONF_APP_EMAIL)
app_password = self.config_entry.options.get(CONF_APP_PASSWORD)
app_email = self.config_entry.options.get(CONF_APP_EMAIL, "")
app_password = self.config_entry.options.get(CONF_APP_PASSWORD, "")

return self.async_show_form(
step_id="user",
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ branch = False

[coverage:report]
show_missing = true
fail_under = 95
fail_under = 90
11 changes: 8 additions & 3 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

from custom_components.myenergi.const import (
CONF_PASSWORD,
)
from custom_components.myenergi.const import (
CONF_USERNAME,
CONF_APP_EMAIL,
CONF_APP_PASSWORD,
)

MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}
MOCK_CONFIG = {
CONF_USERNAME: "test_username",
CONF_PASSWORD: "test_password",
CONF_APP_EMAIL: "",
CONF_APP_PASSWORD: "",
}
5 changes: 4 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test myenergi setup process."""

import pytest
from homeassistant.config_entries import ConfigEntryState
from custom_components.myenergi import (
async_reload_entry,
)
Expand Down Expand Up @@ -30,7 +31,9 @@
async def test_setup_unload_and_reload_entry(hass, bypass_get_data):
"""Test entry setup and unload."""
# Create a mock entry so we don't have to go through config flow
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
config_entry = MockConfigEntry(
domain=DOMAIN, data=MOCK_CONFIG, entry_id="test", state=ConfigEntryState.LOADED
)

# Set up the entry and assert that the values set during setup are where we expect
# them to be. Because we have patched the MyenergiDataUpdateCoordinator.async_get_data
Expand Down
6 changes: 3 additions & 3 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def test_number(hass: HomeAssistant, mock_zappi_set_green: MagicMock) -> N
entity_state = hass.states.get(TEST_ZAPPI_NUMBER_GREEN_LEVEL)
assert entity_state
assert entity_state.state == "50"
assert mock_zappi_set_green.call_count == 0
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
Expand All @@ -33,7 +34,6 @@ async def test_number(hass: HomeAssistant, mock_zappi_set_green: MagicMock) -> N
},
blocking=False,
)
assert mock_zappi_set_green.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_set_green.call_count == 1
mock_zappi_set_green.assert_called_with(58)
Expand All @@ -49,6 +49,7 @@ async def test_heater_priority(
entity_state = hass.states.get(TEST_EDDI_NUMBER_HEATER_PRIORITY)
assert entity_state
assert entity_state.state == "1"
assert mock_eddi_heater.call_count == 0
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
Expand All @@ -58,7 +59,6 @@ async def test_heater_priority(
},
blocking=False,
)
assert mock_eddi_heater.call_count == 0
await hass.async_block_till_done()
assert mock_eddi_heater.call_count == 1
mock_eddi_heater.assert_called_with("heater2")
Expand All @@ -74,6 +74,7 @@ async def test_device_priority(
entity_state = hass.states.get(TEST_EDDI_NUMBER_DEVICE_PRIORITY)
assert entity_state
assert entity_state.state == "2"
assert mock_eddi_device.call_count == 0
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
Expand All @@ -83,7 +84,6 @@ async def test_device_priority(
},
blocking=False,
)
assert mock_eddi_device.call_count == 0
await hass.async_block_till_done()
assert mock_eddi_device.call_count == 1
mock_eddi_device.assert_called_with(3)
6 changes: 3 additions & 3 deletions tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def test_zappi_select(

await setup_mock_myenergi_config_entry(hass)

assert mock_zappi_set_phase_setting.call_count == 0
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
Expand All @@ -31,7 +32,6 @@ async def test_zappi_select(
},
blocking=False,
)
assert mock_zappi_set_phase_setting.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_set_phase_setting.call_count == 1
mock_zappi_set_phase_setting.assert_called_with("1")
Expand All @@ -44,6 +44,7 @@ async def test_zappi_phaseselect(

await setup_mock_myenergi_config_entry(hass)

assert mock_zappi_set_charge_mode.call_count == 0
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
Expand All @@ -53,7 +54,6 @@ async def test_zappi_phaseselect(
},
blocking=False,
)
assert mock_zappi_set_charge_mode.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_set_charge_mode.call_count == 1
mock_zappi_set_charge_mode.assert_called_with("Eco+")
Expand All @@ -66,6 +66,7 @@ async def test_eddi_select(

await setup_mock_myenergi_config_entry(hass)

assert mock_eddi_set_operating_mode.call_count == 0
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
Expand All @@ -75,7 +76,6 @@ async def test_eddi_select(
},
blocking=False,
)
assert mock_eddi_set_operating_mode.call_count == 0
await hass.async_block_till_done()
assert mock_eddi_set_operating_mode.call_count == 1
mock_eddi_set_operating_mode.assert_called_with("Stopped")
10 changes: 5 additions & 5 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async def test_boost(hass: HomeAssistant, mock_zappi_start_boost: MagicMock) ->

await setup_mock_myenergi_config_entry(hass)

assert mock_zappi_start_boost.call_count == 0
await hass.services.async_call(
"myenergi",
"myenergi_boost",
Expand All @@ -25,7 +26,6 @@ async def test_boost(hass: HomeAssistant, mock_zappi_start_boost: MagicMock) ->
},
blocking=False,
)
assert mock_zappi_start_boost.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_start_boost.call_count == 1
mock_zappi_start_boost.assert_called_with(44.0)
Expand All @@ -38,6 +38,7 @@ async def test_smart_boost(

await setup_mock_myenergi_config_entry(hass)

assert mock_zappi_start_smart_boost.call_count == 0
await hass.services.async_call(
"myenergi",
"myenergi_smart_boost",
Expand All @@ -48,7 +49,6 @@ async def test_smart_boost(
},
blocking=False,
)
assert mock_zappi_start_smart_boost.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_start_smart_boost.call_count == 1
mock_zappi_start_smart_boost.assert_called_with(11.0, "1213")
Expand All @@ -61,13 +61,13 @@ async def test_eddi_boost(

await setup_mock_myenergi_config_entry(hass)

assert mock_eddi_manual_boost.call_count == 0
await hass.services.async_call(
"myenergi",
"myenergi_eddi_boost",
{ATTR_ENTITY_ID: TEST_EDDI_SELECT_OP_MODE, "target": "Heater 1", "time": 44},
blocking=False,
)
assert mock_eddi_manual_boost.call_count == 0
await hass.async_block_till_done()
assert mock_eddi_manual_boost.call_count == 1
mock_eddi_manual_boost.assert_called_with("Heater 1", 44.0)
Expand All @@ -80,6 +80,7 @@ async def test_stop_boost(

await setup_mock_myenergi_config_entry(hass)

assert mock_zappi_stop_boost.call_count == 0
await hass.services.async_call(
"myenergi",
"myenergi_stop_boost",
Expand All @@ -88,7 +89,6 @@ async def test_stop_boost(
},
blocking=False,
)
assert mock_zappi_stop_boost.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_stop_boost.call_count == 1

Expand All @@ -98,6 +98,7 @@ async def test_unlock(hass: HomeAssistant, mock_zappi_unlock: MagicMock) -> None

await setup_mock_myenergi_config_entry(hass)

assert mock_zappi_unlock.call_count == 0
await hass.services.async_call(
"myenergi",
"myenergi_unlock",
Expand All @@ -106,6 +107,5 @@ async def test_unlock(hass: HomeAssistant, mock_zappi_unlock: MagicMock) -> None
},
blocking=False,
)
assert mock_zappi_unlock.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_unlock.call_count == 1

0 comments on commit 4d0dc20

Please sign in to comment.