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 configure_reporting() method to zha component #16487

Merged
merged 5 commits into from
Sep 13, 2018

Conversation

Adminiuga
Copy link
Contributor

@Adminiuga Adminiuga commented Sep 8, 2018

Implement zha.configure_reporting() method, which is very similar to zha.safe_read().

most Zigbee devices configure attribute reporting to push state updates to Hass. Currently there's similar code which binds&configure_reporting for a cluster/attribute. This PR moves that code to zha component and handles possible exceptions.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

try:
v = await cluster.bind()
_LOGGER.debug(
"{}: bound '{}' cluster: {}".format(entity_id, cluster_name, v)

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)


try:
res = await cluster.configure_reporting(attr, min_report,
max_report, reportable_change)

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

sensor.value_attribute, 300, 600, sensor.min_reportable_change,
yield from zha.configure_reporting(
sensor.entity_id, cluster, sensor.value_attribute,
reportable_change=sensor.min_reportable_change
Copy link

@ryanwinter ryanwinter Sep 10, 2018

Choose a reason for hiding this comment

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

You dropped the min and max report parameters.

Reverting to the default means the max will change from 600 to 900. Is this important?

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 max_report interval is more of a "keep_alive" update, which is sent even if the attribute hasn't changed. IMO doesn't really matter if it 10min or 15min, but it is more graceful on battery operated devices. The only downside, it is going to be 5 min longer for the status to synchronize if the device was offline for whatever reason.

Once/If this PR gets merged, I'm planning to submit another one where min/max_report interval will be part of base Sensor class, allowing child classes to override those to match sensor specifics.

* use configure_reporting for zha switch

* lint fixes
_LOGGER.debug(
"%s: bound '%s' cluster: %s", entity_id, cluster_name, res[0]
)
except DeliveryError as ex:
Copy link
Member

Choose a reason for hiding this comment

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

Should the method stop execution if this fails?

Copy link
Contributor Author

@Adminiuga Adminiuga Sep 12, 2018

Choose a reason for hiding this comment

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

It is the same idea as behind zha.safe_read() Better to have an entity which may not push external updates (eg manually toggled switch), but still works otherwise and could be controlled, rather than no entity at all.
Some vendors (eg Xiaomi) will throw, but still would send attribute reports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the long run I'm thinking about having it as a "service call" on a device, like in a "repair_device" service call

async_add_entities([sensor], update_before_add=True)


async def make_sensor(discovery_info):
Copy link
Member

Choose a reason for hiding this comment

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

Why is this called sensor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change to switch

await coro
except zigpy.exceptions.DeliveryError as exc:
_LOGGER.warning("Ignoring error during setup: %s", exc)
sensor = Switch(**discovery_info)
Copy link
Member

Choose a reason for hiding this comment

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

sensor = switch ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. I should code less late nights :) i'll fix it

@balloob balloob merged commit f2203e5 into home-assistant:dev Sep 13, 2018
@ghost ghost removed the in progress label Sep 13, 2018
@Adminiuga Adminiuga deleted the zha-configure-reporting branch September 13, 2018 14:53
@balloob balloob mentioned this pull request Sep 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
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.

5 participants