Skip to content

Add Grandstream Home integration#167872

Draft
wtxu-gs wants to merge 2 commits intohome-assistant:devfrom
wtxu-gs:feat/grandstream_home
Draft

Add Grandstream Home integration#167872
wtxu-gs wants to merge 2 commits intohome-assistant:devfrom
wtxu-gs:feat/grandstream_home

Conversation

@wtxu-gs
Copy link
Copy Markdown

@wtxu-gs wtxu-gs commented Apr 10, 2026

This integration adds support for Grandstream GDS/GNS/GSC devices.

Features:

  • System status sensors
  • Zeroconf discovery

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)
  • 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

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@mawoka-myblock
Copy link
Copy Markdown
Contributor

The source for the library is missing: https://github.com/GrandstreamEngineering/grandstream_home_api

@wtxu-gs wtxu-gs force-pushed the feat/grandstream_home branch 4 times, most recently from f443b7c to aa77908 Compare April 10, 2026 08:37
@wtxu-gs
Copy link
Copy Markdown
Author

wtxu-gs commented Apr 10, 2026

The source for the library is missing: https://github.com/GrandstreamEngineering/grandstream_home_api

It is added now

@wtxu-gs wtxu-gs force-pushed the feat/grandstream_home branch from aa77908 to 8a3b791 Compare April 10, 2026 08:43
@wtxu-gs
Copy link
Copy Markdown
Author

wtxu-gs commented Apr 10, 2026

Copy link
Copy Markdown
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

I did an initial review until I stopped as this PR is to huge. Some code needs to move to the library and also the config flow is huge. Please refactor the code and make it more readable.

Also the library needs a working workflow to deploy directly to pypi.
As 10.000 changes is to much, can we just add a single device/model in this PR and then add other models in a follow up PR. This PR needs to be a lot smaller

@home-assistant home-assistant bot marked this pull request as draft April 10, 2026 12:15
@home-assistant
Copy link
Copy Markdown

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.

@wtxu-gs wtxu-gs force-pushed the feat/grandstream_home branch 2 times, most recently from 94772a0 to 62a2b83 Compare April 13, 2026 10:45
@wtxu-gs wtxu-gs marked this pull request as ready for review April 13, 2026 10:45
@home-assistant home-assistant bot requested a review from edenhaus April 13, 2026 10:45
@wtxu-gs wtxu-gs force-pushed the feat/grandstream_home branch from 62a2b83 to 3adbbd7 Compare April 13, 2026 10:58
@wtxu-gs wtxu-gs force-pushed the feat/grandstream_home branch from 3adbbd7 to a5c791e Compare April 13, 2026 10:58
@wtxu-gs wtxu-gs requested a review from joostlek April 13, 2026 11:00
Comment on lines +885 to +886
# Reauthentication Flow
async def async_step_reauth(
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 keep reauth out of the first PR

# Store auth info
self._auth_info = {
CONF_USERNAME: username,
CONF_PASSWORD: encrypt_password(password, self.unique_id or "default"),
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.

Why do we encrypt the password?

Comment on lines +85 to +88
# Initialize global API lock if not exists
hass.data.setdefault(DOMAIN, {})
if "api_lock" not in hass.data[DOMAIN]:
hass.data[DOMAIN]["api_lock"] = asyncio.Lock()
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.

Why do we need a global API lock?

Comment on lines +104 to +106
if error_type == "offline":
_LOGGER.warning("API login failed (device may be offline)")
return
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.

Why does the device need to login to the API?

Comment on lines +108 to +112
if error_type == "ha_control_disabled":
raise ConfigEntryAuthFailed(
"Home Assistant control is disabled on the device. "
"Please enable it in the device web interface."
)
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.

Why can HA control be disabled?

Comment on lines +135 to +155
async def async_handle_push_data(self, data: dict[str, Any]) -> None:
"""Handle pushed data."""
try:
_LOGGER.debug("Received push data: %s", data)
data = process_push_data(data)
self.last_update_method = "push"
self.async_set_updated_data(data)
except Exception as e:
_LOGGER.error("Error processing push data: %s", e)
raise

def handle_push_data(self, data: dict[str, Any]) -> None:
"""Handle push data synchronously."""
try:
_LOGGER.debug("Processing sync push data: %s", data)
data = process_push_data(data)
self.last_update_method = "push"
self.async_set_updated_data(data)
except Exception as e:
_LOGGER.error("Error processing sync push data: %s", e)
raise
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.

Where does this happen

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.

I am not sure what the task of this class is, should this be a base entity instead?

"type": "_https._tcp.local."
},
{
"name": "*",
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.

I think matching on asterisk is too broad

Comment on lines +439 to +480
# Add SIP account sensors (only if accounts exist)
# Track by account ID instead of index
sip_accounts = coordinator.data.get("sip_accounts", [])
for account in sip_accounts:
if isinstance(account, dict):
account_id = account.get("id", "")
if account_id:
entities.extend(
GrandstreamSipAccountSensor(
coordinator, device, description, account_id
)
for description in SIP_ACCOUNT_SENSORS
)
created_sip_sensors.add(account_id)

# Add listener to dynamically add new SIP account sensors
@callback
def _async_add_sip_sensors() -> None:
"""Add new SIP account sensors when accounts are added."""
sip_accounts = coordinator.data.get("sip_accounts", [])
new_entities: list[GrandstreamSipAccountSensor] = []

for account in sip_accounts:
if isinstance(account, dict):
account_id = account.get("id", "")
if account_id and account_id not in created_sip_sensors:
new_entities.extend(
GrandstreamSipAccountSensor(
coordinator, device, description, account_id
)
for description in SIP_ACCOUNT_SENSORS
)
created_sip_sensors.add(account_id)

if new_entities:
async_add_entities(new_entities)

# Register listener
config_entry.async_on_unload(
coordinator.async_add_listener(_async_add_sip_sensors)
)

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.

Can we keep dynamic devices out of this PR

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.

Can we cut this down to a single type of information first and add the rest in later PRs? I think that will make this much more reviewable

@home-assistant home-assistant bot marked this pull request as draft April 14, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants