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

ReadYourMeter Pro integration #85986

Merged
merged 4 commits into from
Jan 24, 2023
Merged

Conversation

OnFreund
Copy link
Contributor

@OnFreund OnFreund commented Jan 16, 2023

Proposed change

A new integration for the Read Your Meter Pro service, which monitors your water usage. Starting this with a single sensor reflecting the last read, and will follow up with additional sensors in the future.

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

To help with the load of incoming pull requests:

homeassistant/components/rympro/manifest.json Outdated Show resolved Hide resolved
homeassistant/components/rympro/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/rympro/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/rympro/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/rympro/config_flow.py Outdated Show resolved Hide resolved
Copy link
Member

@thecode thecode left a comment

Choose a reason for hiding this comment

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

Also tested locally with my meter (including changing the password to trigger reauth), great work!

@thecode thecode merged commit 2c9e8ad into home-assistant:dev Jan 24, 2023
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Please address these in a new PR.

return unload_ok


class RymProDataUpdateCoordinator(DataUpdateCoordinator):
Copy link
Member

Choose a reason for hiding this comment

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

Coordinators should go into their own modules, in this case, move it into coordinator.py.

self._reauth_entry,
title=title,
data=data,
unique_id=info[CONF_UNIQUE_ID],
Copy link
Member

@frenck frenck Jan 24, 2023

Choose a reason for hiding this comment

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

This can't change, right? Why is it updated?

As a matter of fact, what in this re-auth process guards that the right account is re-authed?

Comment on lines +29 to +32
[
RymProSensor(coordinator, meter_id, meter["read"], config_entry.entry_id)
for meter_id, meter in coordinator.data.items()
]
Copy link
Member

Choose a reason for hiding this comment

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

async_add_entities accepts a generator, you can remove the list comprehension here.

class RymProSensor(CoordinatorEntity[RymProDataUpdateCoordinator], SensorEntity):
"""Sensor for RymPro meters."""

_attr_has_entity_name = True
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be incorrect, as there are conditions not met for this to be set.

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 the name to sentence case. Other than that, is there any other condition that's not met?

Copy link
Member

Choose a reason for hiding this comment

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

That's about it as it seems.

"""Sensor for RymPro meters."""

_attr_has_entity_name = True
_attr_name = "Last Read"
Copy link
Member

Choose a reason for hiding this comment

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

This must be following sentence case styling to be able to set has_entity_name.

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, it is a bit of an odd name, it would suggest a date of when it was last read? But I guess it is water usage? Would that be a better name?

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 read here is in present tense, as in the meter read. Common usage, and how the service refers to it, but maybe total consumption? As opposed to some periodic consumption (e.g. daily, monthly), which I plan on adding in future PRs.

Copy link
Member

Choose a reason for hiding this comment

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

We don't describe entities on what they do.. we describe what they are/represent. They represent consumption or usage in this case.

homeassistant/components/rympro/sensor.py Show resolved Hide resolved
homeassistant/components/rympro/sensor.py Show resolved Hide resolved
"""Initialize sensor."""
super().__init__(coordinator)
self._meter_id = meter_id
self._entity_registry: er.EntityRegistry | None = None
Copy link
Member

Choose a reason for hiding this comment

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

This is unused?

Comment on lines +66 to +70
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_native_value = self.coordinator.data[self._meter_id]["read"]
self.async_write_ha_state()
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to handle it like this. The coordinator already has the data and there are no calculations involved here. Implement the native_value property method instead.

Comment on lines +96 to +97
assert result2["type"] == FlowResultType.FORM
assert result2["errors"] == {"base": error}
Copy link
Member

@frenck frenck Jan 24, 2023

Choose a reason for hiding this comment

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

This test is incomplete.

For example, if authentication is incorrect, a user can recover from it. Please make the test complete until the config entry is created (to ensure there are no side-effects from recovering from the error handling).

Copy link
Contributor Author

@OnFreund OnFreund left a comment

Choose a reason for hiding this comment

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

Thanks @frenck!
I will address these in a new PR ASAP. Left some clarification comments/questions in the meantime.

class RymProSensor(CoordinatorEntity[RymProDataUpdateCoordinator], SensorEntity):
"""Sensor for RymPro meters."""

_attr_has_entity_name = True
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 the name to sentence case. Other than that, is there any other condition that's not met?

"""Sensor for RymPro meters."""

_attr_has_entity_name = True
_attr_name = "Last Read"
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 read here is in present tense, as in the meter read. Common usage, and how the service refers to it, but maybe total consumption? As opposed to some periodic consumption (e.g. daily, monthly), which I plan on adding in future PRs.

homeassistant/components/rympro/sensor.py Show resolved Hide resolved
homeassistant/components/rympro/sensor.py Show resolved Hide resolved
@OnFreund OnFreund deleted the rympro_integration branch January 25, 2023 06:29
except UnauthorizedError:
try:
token = await rympro.login(data[CONF_EMAIL], data[CONF_PASSWORD], "ha")
hass.config_entries.async_update_entry(
Copy link
Member

Choose a reason for hiding this comment

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

Please only wrap the line that can raise in the try... except block. Move this line down.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2023
@thecode
Copy link
Member

thecode commented Jan 26, 2023

Follow up PR: #86734

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.

4 participants