Skip to content

Add new integration Loqed#70080

Merged
marcelveldt merged 28 commits into
home-assistant:devfrom
cpolhout:loqed-integration
Jun 28, 2023
Merged

Add new integration Loqed#70080
marcelveldt merged 28 commits into
home-assistant:devfrom
cpolhout:loqed-integration

Conversation

@cpolhout
Copy link
Copy Markdown

@cpolhout cpolhout commented Apr 15, 2022

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cpolhout 👋

This PR has merge conflicts and there are unrelated changes in this PR. Could you take a look?

Thanks!

../Frenck

@MartinHjelmare MartinHjelmare changed the title Added new integration Loqed Add new integration Loqed Apr 19, 2022
@cpolhout
Copy link
Copy Markdown
Author

Hi @frenck

Thanks for reviewing. Yes I see, i removed the changes from my PR. Only the Codeowners-file gives errors now, but I don't know why.
Can you check again. Thanks.
Casper

@cpolhout cpolhout requested a review from frenck April 19, 2022 18:24
@cpolhout

This comment was marked as duplicate.

Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there @cpolhout 👋

Some initial comments to get this started. Additionally:

  • Missing tests. We require configuration flows to have 100% test coverage.
  • What if the lock was not on my internal network? E.g., a remote lock at my parents?
  • Consider moving data handling using a DataUpdateCoordinator
  • How would it handle multiple locks?

../Frenck

Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/lock.py Outdated
Comment thread homeassistant/components/loqed/lock.py Outdated
Comment thread homeassistant/components/loqed/lock.py Outdated
Comment thread homeassistant/components/loqed/lock.py Outdated
Comment thread homeassistant/components/loqed/lock.py
@cpolhout cpolhout mentioned this pull request Jun 6, 2022
21 tasks
@cpolhout
Copy link
Copy Markdown
Author

cpolhout commented Jun 7, 2022

Hi @frenck now updated this PR. Will remove the other one!. Thanks!

@cpolhout
Copy link
Copy Markdown
Author

Hi @frenck , did you have time to review the changes we made?

@cpolhout

This comment was marked as duplicate.

@mikewoudenberg mikewoudenberg force-pushed the loqed-integration branch 2 times, most recently from 3734c7e to 554552d Compare July 10, 2022 09:11
@frenck frenck self-requested a review August 4, 2022 08:44
frenck
frenck previously requested changes Aug 4, 2022
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/strings.json Outdated
Comment thread homeassistant/components/loqed/strings.json Outdated
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/__init__.py Outdated
Comment thread homeassistant/components/loqed/sensor.py Outdated
Comment thread homeassistant/components/loqed/sensor.py Outdated
Comment thread homeassistant/components/loqed/sensor.py Outdated
Comment thread homeassistant/components/loqed/sensor.py Outdated
Comment thread homeassistant/components/loqed/sensor.py Outdated
@riemers
Copy link
Copy Markdown

riemers commented Aug 18, 2022

I don’t know if it is mentioned somewhere. But if you grab the api key from the website (Login there) it logs you out of the mobile app. (Yes it logs you out everywhere) it’s bad but that should be very clear in order to not get an issue bomb.

@frenck
Copy link
Copy Markdown
Member

frenck commented Aug 18, 2022

@mikewoudenberg Do you know what that is? Can that be prevented?

@mikewoudenberg
Copy link
Copy Markdown
Contributor

I don’t know if it is mentioned somewhere. But if you grab the api key from the website (Login there) it logs you out of the mobile app. (Yes it logs you out everywhere) it’s bad but that should be very clear in order to not get an issue bomb.

Yes that is known. It's mentioned on the webpage of the app:
Screenshot 2022-08-18 at 09 56 57

@riemers
Copy link
Copy Markdown

riemers commented Aug 18, 2022

Same reason Frenck mentioned to login to get the api json. People do not read/lesser user friendly. A warning on the HA side would be good too.

@frenck
Copy link
Copy Markdown
Member

frenck commented Aug 18, 2022

I don't think this should be a warning it at all, in my opinion, it should not log people out. There is no reason for such behavior in modern-day applications. It almost feels like deliberately torturing people doing so. Don't frustrate end-users, that is not needed at all.

@riemers
Copy link
Copy Markdown

riemers commented Aug 18, 2022

Totally agree with that, but that is currently not in our control. Perhaps Mike has closer contacts to get the word out.

@mikewoudenberg
Copy link
Copy Markdown
Contributor

The logging out after logging in on the webapp is being looked in to fortunately

@mikewoudenberg
Copy link
Copy Markdown
Contributor

The logging out issue has been resolved. The user will no longer be logged out of the native app when logging into the Webapp to copy the setup config. Supporting other types of logging in will take considerable more effort so I don't expect that anytime soon. So I was wondering what kind of next steps you expect from my side to land this pr. I'll start by rebasing it on current develop obviously

Comment thread tests/components/loqed/test_sensor.py Outdated
Comment thread homeassistant/components/loqed/config_flow.py Outdated
Comment thread homeassistant/components/loqed/config_flow.py
Comment thread homeassistant/components/loqed/config_flow.py
Comment thread homeassistant/components/loqed/strings.json
@marcelveldt
Copy link
Copy Markdown
Member

CI failing on one of the tests, otherwise fine

Copy link
Copy Markdown
Member

@marcelveldt marcelveldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!
Let's try to improve the setup flow later once this is possible upstream, for now this is totally fine.

Only change left is fix the test so that CI passes. Once that is done this can be merged imo.

@mikewoudenberg
Copy link
Copy Markdown
Contributor

Very nice, thanks! Let's try to improve the setup flow later once this is possible upstream, for now this is totally fine.

Only change left is fix the test so that CI passes. Once that is done this can be merged imo.

Fixed them (forgot to push the updated tests).

@mikewoudenberg
Copy link
Copy Markdown
Contributor

mikewoudenberg commented Jun 23, 2023

Very nice, thanks! Let's try to improve the setup flow later once this is possible upstream, for now this is totally fine.

Only change left is fix the test so that CI passes. Once that is done this can be merged imo.

I pushed the fixed tests, but now CI is still failing? Seems to be running into a timeout.

@marcelveldt
Copy link
Copy Markdown
Member

kicked CI as it was indeed failing on something unrelated.

@marcelveldt
Copy link
Copy Markdown
Member

Thanks @mikewoudenberg !

@marcelveldt marcelveldt merged commit cfb133d into home-assistant:dev Jun 28, 2023
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments in a new PR. Thanks!

lock_data = await cloud_client.async_get_locks()
except aiohttp.ClientError:
_LOGGER.error("HTTP Connection error to loqed API")
raise CannotConnect from aiohttp.ClientError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please raise from the exception instance in this scope instead.

except SomeException as err:
    raise AnotherException from err

except InvalidAuth:
errors["base"] = "invalid_auth"
else:
await self.async_set_unique_id(
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass raise_on_progress=False to make the user flow always take precedence over the discovered flow.



DOMAIN = "loqed"
OAUTH2_AUTHORIZE = "https://app.loqed.com/API/integration_oauth3/login.php"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants don't appear to be used.

Does the api support oauth2?

) -> None:
"""Initialize the Loqed Data Update coordinator."""
super().__init__(hass, _LOGGER, name="Loqed sensors")
self._hass = hass
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hass is set in the parent.

async with async_timeout.timeout(10):
return await self._api.async_get_lock_details()

@callback
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A coroutine function is not a callback.

@property
def changed_by(self) -> str:
"""Return internal ID of last used key."""
return "KeyID " + str(self._lock.last_key_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use f-strings instead of string concatenation.

"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unknown string is never used.

@@ -0,0 +1,22 @@
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't source translations anymore. Please remove this file.

coordinator = hass.data[DOMAIN][integration.entry_id]
lock.receiveWebhook = AsyncMock(return_value={"error": "invalid hash"})

with patch.object(coordinator, "async_set_updated_data") as mock:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't patch the coordinator. That's an integration detail. Only assert some core state, eg an entity state in the state machine, or a patched library instance.

https://developers.home-assistant.io/docs/development_testing#writing-tests-for-integrations

"""Tests the lock responding to updates."""
coordinator: LoqedDataCoordinator = hass.data[DOMAIN][integration.entry_id]
lock.bolt_state = "night_lock"
coordinator.async_update_listeners()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move time forward to trigger an update instead.

core/tests/common.py

Lines 394 to 397 in 98a94fe

@callback
def async_fire_time_changed(
hass: HomeAssistant, datetime_: datetime | None = None, fire_all: bool = False
) -> None:

@mikewoudenberg mikewoudenberg deleted the loqed-integration branch June 28, 2023 08:58
@mikewoudenberg
Copy link
Copy Markdown
Contributor

Thanks for the feedback I'll create a follow-up PR to address these issues.

@github-actions github-actions Bot locked and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.