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 Wyoming satellite #104759

Merged
merged 18 commits into from Dec 4, 2023
Merged

Add Wyoming satellite #104759

merged 18 commits into from Dec 4, 2023

Conversation

synesthesiam
Copy link
Contributor

@synesthesiam synesthesiam commented Nov 29, 2023

Breaking change

Proposed change

NOTE: Tests still need to be added.

Raspberry Pi voice satellites currently use the websocket API, which does not allow them to be proper HA devices with an area and HA controls/sensors like ESPHome and VoIP.

This PR adds a "Wyoming Satellite", which uses recent additions to the Wyoming protocol to include:

  • Discovery of Wyoming satellites (or any Wyoming service) over zeroconf
  • Bi-direction communication with a satellite over TCP (Wyoming protocol)
  • An HA device per satellite with:
    • A pipeline select
    • An "Assist in progress" sensor
    • A "Satellite enabled" switch for disabling the satellite when not needed

Two satellite modes are supported (controlled by the satellite):

  1. "Remote" wake word detection on HA - audio is continuously streamed
  2. "Local" wake word detection on the satellite - audio is only streamed after wake word detection

A reference implementation of the satellite client is available in the wyoming-satellite project.

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 Ruff (ruff format 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
Copy link

Hey there @balloob, mind taking a look at this pull request as it has been labeled with an integration (wyoming) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of wyoming can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign wyoming Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@synesthesiam synesthesiam marked this pull request as ready for review November 30, 2023 15:35
Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Looking pretty good. Few minor comments.

@home-assistant home-assistant bot marked this pull request as draft December 3, 2023 04:59
@home-assistant
Copy link

home-assistant bot commented Dec 3, 2023

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.

@synesthesiam synesthesiam marked this pull request as ready for review December 3, 2023 20:43
@home-assistant home-assistant bot requested a review from balloob December 3, 2023 20:43
@balloob balloob added this to the 2023.12.0 milestone Dec 4, 2023
)
platforms = item.service.platforms
if item.satellite is not None:
platforms += SATELLITE_PLATFORMS
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
platforms += SATELLITE_PLATFORMS
platforms = platforms + SATELLITE_PLATFORMS

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I think this suggestion isn't an improvement...

Copy link
Member

Choose a reason for hiding this comment

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

The intent is to not change the original variable anymore

@balloob balloob merged commit a9381d2 into dev Dec 4, 2023
52 of 53 checks passed
@balloob balloob deleted the synesthesiam-20231116-wyoming-satellite branch December 4, 2023 20:13
Copy link
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.

The new platforms only seem to calculate state themselves without state input from a device or service. The binary sensor is borderline as it interprets pipeline events as state, if I understand correctly. The select and switch entities look like virtual config entities. We don't allow this normally.

return WyomingSatellite(hass, service, satellite_device)


async def update_listener(hass: HomeAssistant, entry: ConfigEntry):
Copy link
Member

Choose a reason for hiding this comment

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

Missing return value typing.


# Use zeroconf name + service name as unique id.
# The satellite will use its own MAC as the zeroconf name by default.
unique_id = f"{discovery_info.name}_{self._name}"
Copy link
Member

Choose a reason for hiding this comment

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

Use the local variable name instead of the attribute.

)

return self.async_create_entry(
title=self._name,
Copy link
Member

Choose a reason for hiding this comment

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

Define a local variable when accessing an attribute more than once.

def __init__(self, device: SatelliteDevice) -> None:
"""Initialize entity."""
self._device = device
self._attr_unique_id = f"{device.satellite_id}-{self.entity_description.key}"
Copy link
Member

Choose a reason for hiding this comment

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

There's no entity description attribute set. It needs to be set here in the parent if we need to use it here.

"""Run when run() has fully stopped."""
_LOGGER.debug("Satellite task stopped")

# -------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

What do the dashes mean?

"""Turn on."""
self._attr_is_on = True
self.async_write_ha_state()
self._device.set_is_enabled(True)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we change the device after updating the entity state and not before? Normally the entity should reflect the device feature state and not the other way around.

item.satellite = _make_satellite(hass, entry, service)

# Set up satellite sensors, switches, etc.
await hass.config_entries.async_forward_entry_setups(entry, SATELLITE_PLATFORMS)
Copy link
Member

Choose a reason for hiding this comment

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

Note that it would be an error if we tried to forward the config entry more than once to a platform. There's no overlap at the moment, and I guess it would be caught in tests.

hass: HomeAssistant, init_satellite, satellite_config_entry: ConfigEntry
) -> SatelliteDevice:
"""Get a satellite device fixture."""
return hass.data[DOMAIN][satellite_config_entry.entry_id].satellite.device
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 hass.data in tests.

state = hass.states.get(assist_in_progress_id)
assert state is not None
assert state.state == STATE_OFF
assert not satellite_device.is_active
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 assert the device. It's a detail of the integration.

assert hass.states.get(pipeline_entity_id) is not None

# Remove
device_registry.async_remove_device(satellite_device.device_id)
Copy link
Member

Choose a reason for hiding this comment

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

Removing a device and checking that the entity state is gone is more testing the device registry than testing this integration.

frenck pushed a commit that referenced this pull request Dec 5, 2023
* First draft of Wyoming satellite

* Set up homeassistant in tests

* Move satellite

* Add devices with binary sensor and select

* Add more events

* Add satellite enabled switch

* Fix mistake

* Only set up necessary platforms for satellites

* Lots of fixes

* Add tests

* Use config entry id as satellite id

* Initial satellite test

* Add satellite pipeline test

* More tests

* More satellite tests

* Only support single device per config entry

* Address comments

* Make a copy of platforms
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 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.

None yet

4 participants