Skip to content

Add zha typing [api] (2)#68335

Merged
frenck merged 1 commit intohome-assistant:devfrom
cdce8p:zha-api_2
Mar 18, 2022
Merged

Add zha typing [api] (2)#68335
frenck merged 1 commit intohome-assistant:devfrom
cdce8p:zha-api_2

Conversation

@cdce8p
Copy link
Copy Markdown
Member

@cdce8p cdce8p commented Mar 18, 2022

Proposed change

Followup to #68220
Continue typing zha/api.py.

  • Use ZHAGateway instead of ZhaGatewayType. Type checkers can't handle the redefinition from str to a type in core/typing.py. A temporary fix would be to put the str defs in the else clause for if TYPE_CHECKING. However it's much better to use the correct types directly anyway. -> With the next PRs, I'll successively replace these aliases.
  • Add annotation for hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] -> ZHAGateway
  • Add annotations for variables which come from websocket msg dicts.
  • Add annotations for variables which come from service data dicts.

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @dmulcahey, @Adminiuga, mind taking a look at this pull request as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
ieee = msg[ATTR_IEEE]
zha_gateway: ZHAGateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
ieee: EUI64 = msg[ATTR_IEEE]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Typing for msg[ATTR_IEEE] isn't perfect yet, since the validator EUI64.convert could also return None if None is passed. Thus technically all ieee variables should be EUI64 | None.

That is unpractical as almost always only EUI64 is expected. For now I decided to use the optional variant only in combination with msg.get(ATTR_IEEE).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To followup on it, I checked all websocket endpoints and service calls. As expected, almost all values for IEEE are required and thus it's safe to assume EUI64 for ATTR_IEEE. The exception here is the ´permit´ service / endpoint that is the only one for which it's optional.

PR to update the schema validators: #68353

@cdce8p cdce8p added the smash Indicator this PR is close to finish for merging or closing label Mar 18, 2022
@frenck frenck merged commit ffcc02e into home-assistant:dev Mar 18, 2022
@cdce8p cdce8p deleted the zha-api_2 branch March 18, 2022 18:09
@cdce8p cdce8p mentioned this pull request Mar 19, 2022
22 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed code-quality integration: zha smash Indicator this PR is close to finish for merging or closing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants