zigpy / zha

Zigbee Home Automation
Apache License 2.0
10 stars 4 forks source link

Provide metadata for the calculation of extra_state_attributes #56

Closed dmulcahey closed 1 month ago

dmulcahey commented 1 month ago

Usage in HA. Done this way to account for the potential future where properties are removed and we only have dicts shared from the lib to HA.

    @property
    def extra_state_attributes(self) -> Mapping[str, Any] | None:
        """Return entity specific state attributes."""
        if self.entity_data.entity.extra_state_attribute_names is not None:
            state_data = self.entity_data.entity.state
            extra_state_attributes = {}
            for name in self.entity_data.entity.extra_state_attribute_names:
                if name in state_data and state_data[name] is not None:
                    extra_state_attributes[name] = state_data[name]
            return extra_state_attributes
        return None
codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.89%. Comparing base (ad272d1) to head (34cad7a).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #56 +/- ## ======================================= Coverage 94.89% 94.89% ======================================= Files 61 61 Lines 9064 9076 +12 ======================================= + Hits 8601 8613 +12 Misses 463 463 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.