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 deako integration using pydeako #102190

Closed
wants to merge 32 commits into from

Conversation

Balake
Copy link
Contributor

@Balake Balake commented Oct 17, 2023

Proposed change

Add Deako integration to connect to Deako devices locally and interact with them. Uses the pydeako library.

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)
  • Deprecation (breaking change to happen in the future)
  • 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
  • I have followed the perfect PR recommendations
  • 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.

To help with the load of incoming pull requests:

home-assistant[bot]

This comment was marked as outdated.

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft October 17, 2023 23:13
@Balake Balake marked this pull request as ready for review October 17, 2023 23:22
@Balake Balake marked this pull request as draft October 17, 2023 23:31
@Balake Balake marked this pull request as ready for review October 17, 2023 23:32
@Balake Balake marked this pull request as draft October 18, 2023 00:26
@Balake Balake marked this pull request as ready for review October 18, 2023 00:28
@Balake Balake marked this pull request as draft October 18, 2023 00:36
@Balake Balake marked this pull request as ready for review October 18, 2023 00:36
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @Balake

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft October 18, 2023 00:38
@Balake Balake marked this pull request as ready for review October 18, 2023 00:39
@Balake
Copy link
Contributor Author

Balake commented Nov 3, 2023

@joostlek I believe I have addressed your comments. Usually I would let the reviewer resolve them, is that the process here?

@joostlek
Copy link
Member

If you think you resolved comments, feel free to resolve them

homeassistant/components/deako/__init__.py Outdated Show resolved Hide resolved

async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered."""
_zc = await zeroconf.async_get_instance(hass)
Copy link
Member

Choose a reason for hiding this comment

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

If we're using zeroconf, why aren't we setting up the devices with 1 device = 1 config entry? (note, I don't have much experience with zeroconf, but please explain a bit more on how the device works)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah for sure. Good question. We have some devices that can discovered with mdns. We pick one to the be "bridge". It can be any of them that are on wifi at the time. That device is then responsible for bridging tcp to ble as not all deako devices are on wifi at all times. Once a device is selected to be the bridge, it will stay on wifi as the local integration device. All other devices periodically get on wifi to check in, send logs, etc.

Since we only really connect to one device, one config entry. All other devices are then exposed through that device using the local API.

Copy link
Member

Choose a reason for hiding this comment

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

What if that bridge node breaks down? What will happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pydeako library handles that. There's a connection watch that if for whatever reason the socket disconnects, another one is spawned, grabbing another address from zeroconf advertisements. All of the connection logic is wrapped in a client which Home Assistant gets an instance of.

In the case that the device that was connected to goes offline (ie power pulled, etc), its mdns entry is removed and so that address wouldn't be picked again, but rather some other address that is active and advertising.

homeassistant/components/deako/const.py Outdated Show resolved Hide resolved
homeassistant/components/deako/light.py Outdated Show resolved Hide resolved
homeassistant/components/deako/light.py Outdated Show resolved Hide resolved
homeassistant/components/deako/light.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft November 13, 2023 19:52
@Balake Balake marked this pull request as ready for review December 7, 2023 18:47

connection = Deako(discoverer.get_address)

hass.data.setdefault(DOMAIN, {})[entry.entry_id] = connection
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to under ConfigEntryNotReady? This way we only populate the hass.data when everything succeeds.

# Base component constants
NAME = "Deako"
DOMAIN = "deako"
DOMAIN_DATA = f"{DOMAIN}_data"
Copy link
Member

Choose a reason for hiding this comment

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

Unused

DOMAIN_DATA = f"{DOMAIN}_data"

# Data keys
CONNECTION_ID = "connection_id"
Copy link
Member

Choose a reason for hiding this comment

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

Unused

Comment on lines +31 to +35
if len(devices) == 0:
# If deako devices are advertising on mdns, we should be able to get at least one device
_LOGGER.warning("No devices found from local integration")
await client.disconnect()
return
Copy link
Member

Choose a reason for hiding this comment

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

Didn't we check for this in the __init__.py?


_attr_has_entity_name = True
_attr_name = None
_attr_is_on = False
Copy link
Member

Choose a reason for hiding this comment

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

Should this be False? I think the default is None which is unknown which looks like a more valid state

Comment on lines +99 to +104
if mock_devices.get_state(device_uuid).get("dim") is not None:
# test that internal dim of 0-100 gets converted properly
assert (
state.attributes.get(ATTR_BRIGHTNESS)
== mock_devices.get_state(device_uuid)["convertedDim"]
)
Copy link
Member

Choose a reason for hiding this comment

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

idem

Comment on lines +111 to +115
if mock_devices.get_state(device_uuid).get("dim") is not None:
assert ColorMode.BRIGHTNESS in entity.capabilities.get("supported_color_modes")
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
else:
assert ColorMode.ONOFF in entity.capabilities.get("supported_color_modes")
Copy link
Member

Choose a reason for hiding this comment

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

Idem

Comment on lines +120 to +124
assert (
device.model == "dimmer"
if mock_devices.get_state(device_uuid).get("dim") is not None
else "smart"
)
Copy link
Member

Choose a reason for hiding this comment

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

Idem

await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

hass.data[DOMAIN][mock_config_entry.entry_id] = pydeako_deako_mock
Copy link
Member

Choose a reason for hiding this comment

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

Don't access internals

await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

hass.data[DOMAIN][mock_config_entry.entry_id] = pydeako_deako_mock
Copy link
Member

Choose a reason for hiding this comment

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

Idem

@home-assistant home-assistant bot marked this pull request as draft January 2, 2024 21:39
Copy link

github-actions bot commented Mar 2, 2024

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Mar 2, 2024
@Balake
Copy link
Contributor Author

Balake commented Mar 2, 2024

Planning on coming back to this soon!

@github-actions github-actions bot removed the stale label Mar 3, 2024
Copy link

github-actions bot commented May 2, 2024

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label May 2, 2024
@github-actions github-actions bot closed this May 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
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.

3 participants