Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mypermobil integration #95613

Merged
merged 54 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8ef5c87
add new integration MyPermobil
IsakNyberg Jun 28, 2023
f306e30
add config flow test
IsakNyberg Jun 29, 2023
bf36a2e
improve documentation
IsakNyberg Jun 30, 2023
4d82753
update permobil api version
IsakNyberg Jun 30, 2023
4053ae7
bump MyPermobil version to 0.1.3
IsakNyberg Jul 3, 2023
e48ee3a
add handling error in sensor setup entry
IsakNyberg Jul 4, 2023
6fbc7ef
remove unnecessary information in manifest
IsakNyberg Jul 25, 2023
42c0910
add coordinator
IsakNyberg Jul 25, 2023
2b06cc7
remove redundant strings
IsakNyberg Jul 25, 2023
33fce5d
change sensor classes to sensor descriptions
IsakNyberg Jul 26, 2023
40bc8b3
Merge branch 'dev' into mypermobil
IsakNyberg Jul 26, 2023
3cf4820
remove coordinator dict inside hass.data
IsakNyberg Jul 26, 2023
d5960df
add translation to sensors
IsakNyberg Jul 26, 2023
81e6fb3
revise sensor states and classes
IsakNyberg Jul 26, 2023
c05160a
add return value for coordinator
IsakNyberg Jul 26, 2023
370057d
change config_entry title and id to user email
IsakNyberg Jul 28, 2023
19385b0
Merge branch 'dev' into mypermobil
IsakNyberg Sep 21, 2023
c7f0968
update imports to comply with ruff check
IsakNyberg Sep 21, 2023
e0515ad
add coordinator and init to .coveragerc
IsakNyberg Sep 21, 2023
09bc77d
address comments on pr
IsakNyberg Oct 11, 2023
48baa67
replace async_timeout with asyncio.timeout
IsakNyberg Oct 11, 2023
6d8dc64
improve config_flow schema
IsakNyberg Oct 12, 2023
41b129c
remove whitespace replacement from email
IsakNyberg Oct 12, 2023
8e4a8fb
update error dict format
IsakNyberg Oct 12, 2023
7720f48
add reauth config flow
IsakNyberg Oct 14, 2023
3cb76e3
remove non-essential comments and code
IsakNyberg Oct 15, 2023
e72294b
remove initialization check for api in config flow
IsakNyberg Oct 15, 2023
fe740e1
fix formatting
IsakNyberg Oct 16, 2023
742ed84
update verification method in config flow
IsakNyberg Oct 17, 2023
4d4d47a
remove verification for empty email code
IsakNyberg Oct 17, 2023
58a1c83
move config flow api initialization to init
IsakNyberg Oct 17, 2023
3666261
update loggin strings
IsakNyberg Oct 17, 2023
5228930
small fix to if statements
IsakNyberg Oct 18, 2023
b251452
add abort for reauth error
IsakNyberg Oct 19, 2023
8f0dcbc
bump mypermobil to 0.1.6
IsakNyberg Oct 19, 2023
f9f0262
Merge branch 'dev' into mypermobil
frenck Oct 19, 2023
b792441
small fixes
IsakNyberg Oct 24, 2023
e789366
overhaul tests
IsakNyberg Oct 26, 2023
28f21d1
fix sensor descriptions keys
IsakNyberg Oct 26, 2023
4aa296d
add marge init test with config flow test
IsakNyberg Oct 26, 2023
500e513
add availability property to sensor
IsakNyberg Oct 26, 2023
876c806
change set_email function to mock
IsakNyberg Oct 28, 2023
31023ab
fix test warnings
IsakNyberg Oct 30, 2023
a2a1eb5
change key to string
IsakNyberg Oct 30, 2023
f1b95e4
add available_fn to all sensors
IsakNyberg Oct 30, 2023
cdab8be
update sensor function types
IsakNyberg Oct 31, 2023
67e2a0e
add separate reauth flow tests
IsakNyberg Oct 31, 2023
b6e4b3e
add icons to some sensors
IsakNyberg Oct 31, 2023
a067794
add data entry check to reauth flow test
IsakNyberg Nov 6, 2023
d9ac205
fix data dict comparions in test
IsakNyberg Nov 18, 2023
498435e
add mock spec
IsakNyberg Nov 21, 2023
6040d58
Merge branch 'dev' into mypermobil
edenhaus Nov 24, 2023
9726d50
Remove MOCK_SPEC class
edenhaus Nov 24, 2023
54c599d
clean up
edenhaus Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
clean up
  • Loading branch information
edenhaus committed Nov 24, 2023
commit 54c599d69a54c5adf0cafe232fd0fd6e6e52a1d8
74 changes: 9 additions & 65 deletions tests/components/permobil/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
MOCK_CODE = "012345"
MOCK_EMAIL = "valid@email.com"
INVALID_EMAIL = "this is not a valid email"
EXPECTED_DATA = {
VALID_DATA = {
CONF_EMAIL: MOCK_EMAIL,
CONF_REGION: MOCK_URL,
CONF_CODE: MOCK_CODE,
Expand Down Expand Up @@ -61,46 +61,7 @@ async def test_sucessful_config_flow(hass: HomeAssistant, my_permobil: Mock) ->
)

assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == EXPECTED_DATA


async def test_sucessful_config_flow_fail_reauth(
hass: HomeAssistant, my_permobil: Mock
) -> None:
"""Test the config flow from start to finish with no errors."""
# init flow
with patch(
"homeassistant.components.permobil.config_flow.MyPermobil",
return_value=my_permobil,
):
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": config_entries.SOURCE_USER},
data={CONF_EMAIL: MOCK_EMAIL},
)

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "region"
assert result["errors"] == {}

# select region step
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_REGION: MOCK_REGION_NAME},
)

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "email_code"
assert result["errors"] == {}

# request region code
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={CONF_CODE: MOCK_CODE},
)

assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == EXPECTED_DATA
assert result["data"] == VALID_DATA


async def test_config_flow_incorrect_code(
Expand Down Expand Up @@ -228,15 +189,10 @@ async def test_config_flow_reauth_success(
reauth_token = ("b" * 256, "reauth_date")
reauth_code = "567890"
my_permobil.request_application_token.return_value = reauth_token

mock_entry = MockConfigEntry(
domain="permobil",
data={
CONF_EMAIL: MOCK_EMAIL,
CONF_REGION: MOCK_URL,
CONF_CODE: MOCK_CODE,
CONF_TOKEN: MOCK_TOKEN[0],
CONF_TTL: MOCK_TOKEN[1],
},
data=VALID_DATA,
)
mock_entry.add_to_hass(hass)

Expand All @@ -263,9 +219,9 @@ async def test_config_flow_reauth_success(
assert result["data"] == {
CONF_EMAIL: MOCK_EMAIL,
CONF_REGION: MOCK_URL,
CONF_CODE: reauth_code, # new value
CONF_TOKEN: reauth_token[0], # new value
CONF_TTL: reauth_token[1], # new value
CONF_CODE: reauth_code,
CONF_TOKEN: reauth_token[0],
CONF_TTL: reauth_token[1],
}


Expand All @@ -278,13 +234,7 @@ async def test_config_flow_reauth_fail_invalid_code(
my_permobil.request_application_token.side_effect = MyPermobilAPIException
mock_entry = MockConfigEntry(
domain="permobil",
data={
CONF_EMAIL: MOCK_EMAIL,
CONF_REGION: MOCK_URL,
CONF_CODE: MOCK_CODE,
CONF_TOKEN: MOCK_TOKEN[0],
CONF_TTL: MOCK_TOKEN[1],
},
data=VALID_DATA,
)
mock_entry.add_to_hass(hass)

Expand Down Expand Up @@ -319,13 +269,7 @@ async def test_config_flow_reauth_fail_code_request(
my_permobil.request_application_code.side_effect = MyPermobilAPIException
mock_entry = MockConfigEntry(
domain="permobil",
data={
CONF_EMAIL: MOCK_EMAIL,
CONF_REGION: MOCK_URL,
CONF_CODE: MOCK_CODE,
CONF_TOKEN: MOCK_TOKEN[0],
CONF_TTL: MOCK_TOKEN[1],
},
data=VALID_DATA,
)
mock_entry.add_to_hass(hass)
# test the reauth and have request_application_code fail leading to an abort
Expand Down
Loading