Skip to content

Conversation

@barneyonline
Copy link
Contributor

Proposed change

  • add sensor platform powered by the shared coordinator
  • surface watering status, standby, freeze prevent, and diagnostic values
  • extend icons/translations
  • add platform tests for the new entities

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @h3l1o5, mind taking a look at this pull request as it has been labeled with an integration (yardian) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of yardian can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign yardian Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@barneyonline barneyonline marked this pull request as ready for review September 26, 2025 07:17
@joostlek joostlek marked this pull request as draft September 26, 2025 10:13
@joostlek
Copy link
Member

Putting to draft as the comments in the binary sensor PR also apply here. But feel free to just do one at a time if you're not sure if you understood what I was saying, otherwise you'd waste too much time trying to get both PRs ready only to update them even more later :)

@barneyonline barneyonline mentioned this pull request Sep 27, 2025
21 tasks
@barneyonline
Copy link
Contributor Author

Putting to draft as the comments in the binary sensor PR also apply here. But feel free to just do one at a time if you're not sure if you understood what I was saying, otherwise you'd waste too much time trying to get both PRs ready only to update them even more later :)

Thanks! I've made similar changes here - let me know what you think

@barneyonline barneyonline marked this pull request as ready for review September 27, 2025 02:17
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Feel free to send me a message on Discord :)

@home-assistant home-assistant bot marked this pull request as draft October 9, 2025 17:48
@home-assistant
Copy link

home-assistant bot commented Oct 9, 2025

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.

@barneyonline barneyonline marked this pull request as ready for review October 20, 2025 07:07
@home-assistant home-assistant bot requested a review from joostlek October 20, 2025 07:07
@joostlek
Copy link
Member

Double checking, you seem to have resolved the unique id suffix discussions but didn't change any code related to that, mind elaborating so I understand your opinion on that suggestion?

@home-assistant home-assistant bot marked this pull request as draft October 20, 2025 07:27
@joostlek
Copy link
Member

Be sure to take a look at the binary sensor tests and the switch ones, I think you can make great tests for this :)

@barneyonline barneyonline force-pushed the yardian-sensors-expansion branch from 7d47885 to 13ceff0 Compare November 1, 2025 22:13
@barneyonline
Copy link
Contributor Author

Double checking, you seem to have resolved the unique id suffix discussions but didn't change any code related to that, mind elaborating so I understand your opinion on that suggestion?

Apologies I overrode the change - have now updated the sensor unique IDs to use the entity key suffix (yid_) instead of custom strings

@barneyonline barneyonline marked this pull request as ready for review November 2, 2025 00:50
@home-assistant home-assistant bot requested a review from joostlek November 2, 2025 00:50

try:
return max(0, int(val))
except (TypeError, ValueError):
Copy link
Member

Choose a reason for hiding this comment

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

why do we catch type errors or value errors? as in, that would only be the case if val is not a value that is a stringified int. But do we actually expect this? Or are these just safeguards for the sake of it? Because in case of the latter I would just remove them as it's obsolete

Copy link
Member

Choose a reason for hiding this comment

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

This wasn't answered. As in, I am not saying it's wrong, I am trying to understand why we do this :)

Comment on lines 58 to 61
try:
delay = int(val)
except (TypeError, ValueError):
return None
Copy link
Member

Choose a reason for hiding this comment

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

idem

@home-assistant home-assistant bot marked this pull request as draft November 2, 2025 04:58
@barneyonline barneyonline marked this pull request as ready for review November 4, 2025 04:53
@home-assistant home-assistant bot requested a review from joostlek November 4, 2025 04:53
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

I think this is going in the direction and is almost there, one main question and you should have all comments on the tests now

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryError
from homeassistant.exceptions import ConfigEntryAuthFailed
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.exceptions import ConfigEntryError

raise UpdateFailed("Timeout communicating with device") from e
except NotAuthorizedException as e:
raise ConfigEntryError("Invalid access token") from e
raise ConfigEntryAuthFailed("Invalid access token") from e
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise ConfigEntryAuthFailed("Invalid access token") from e
raise ConfigEntryError("Invalid access token") from e

The yardian integration doesn't have a reauth flow yet, so we should keep raising error (next to the fact that this isn't in the scope of this PR)


try:
return max(0, int(val))
except (TypeError, ValueError):
Copy link
Member

Choose a reason for hiding this comment

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

This wasn't answered. As in, I am not saying it's wrong, I am trying to understand why we do this :)

from .const import DOMAIN
from .coordinator import YardianUpdateCoordinator

_OPER_INFO_ABSOLUTE_THRESHOLD = 365 * 24 * 3600
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can add a comment mentioning what this value is

Comment on lines +76 to +77
client.start_irrigation = AsyncMock()
client.stop_irrigation = AsyncMock()
Copy link
Member

Choose a reason for hiding this comment

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

With autospec set to True, we don't have to explicitly set this

Comment on lines +50 to +57
mock_yardian_client: object,
) -> None:
"""Diagnostic sensors are disabled by default but report values when enabled."""

with patch("homeassistant.components.yardian.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry)

ent_reg = er.async_get(hass)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mock_yardian_client: object,
) -> None:
"""Diagnostic sensors are disabled by default but report values when enabled."""
with patch("homeassistant.components.yardian.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry)
ent_reg = er.async_get(hass)
mock_yardian_client: object,
entity_registry: er.EntityRegistry,
) -> None:
"""Diagnostic sensors are disabled by default but report values when enabled."""
with patch("homeassistant.components.yardian.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry)

It can just be loaded as test fixture

Comment on lines +68 to +86
def _set_oper_info(
coordinator: YardianUpdateCoordinator, updates: Mapping[str, object]
) -> None:
"""Update coordinator data with new oper_info values."""
device_state = coordinator.data
assert device_state is not None
oper_info_source = getattr(device_state, "oper_info", {})
try:
oper_info = dict(oper_info_source)
except TypeError:
oper_info = {}
oper_info.update(updates)
coordinator.async_set_updated_data(
YardianCombinedState(
zones=device_state.zones,
active_zones=device_state.active_zones,
oper_info=oper_info,
)
)
Copy link
Member

Choose a reason for hiding this comment

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

Not quite. We should not touch internals like the coordinator in hass.data or entry.runtime_data.

Instead we should just update the return value of the mock, and then use freezer to skip time (which would then trigger the update "normally" as it would in real life as time passed by

Comment on lines +99 to +113
async def test_rain_delay_value_handles_invalid_data(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_yardian_client: object,
) -> None:
"""Rain delay sensor converts integers and ignores invalid data."""
coordinator = await _prepare_coordinator(hass, mock_config_entry)

assert _rain_delay_value(coordinator) == 3600

_set_oper_info(coordinator, {"iRainDelay": "bad-value"})
assert _rain_delay_value(coordinator) is None

_set_oper_info(coordinator, {"iRainDelay": None})
assert _rain_delay_value(coordinator) is None
Copy link
Member

Choose a reason for hiding this comment

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

And for this test, to continue on my last comment, I don't really care that _rain_delay_value return a certain value, I want to see how that value is used. afaik it's a state, so have HA setup the integration and then just look at the state of the sensor instead.

Comment on lines +116 to +139
async def test_zone_delay_value_interprets_timestamp_and_errors(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_yardian_client: object,
) -> None:
"""Zone delay interprets timestamps and guards against invalid values."""
coordinator = await _prepare_coordinator(hass, mock_config_entry)

assert _zone_delay_value(coordinator) == 5

frozen_now = datetime(2024, 1, 1, tzinfo=UTC)
with patch(
"homeassistant.components.yardian.sensor.dt_util.utcnow",
return_value=frozen_now,
):
absolute_delay = int(frozen_now.timestamp()) + 120
_set_oper_info(coordinator, {"iSensorDelay": absolute_delay})
assert _zone_delay_value(coordinator) == 120

_set_oper_info(coordinator, {"iSensorDelay": "invalid"})
assert _zone_delay_value(coordinator) is None

_set_oper_info(coordinator, {"iSensorDelay": None})
assert _zone_delay_value(coordinator) is None
Copy link
Member

Choose a reason for hiding this comment

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

You want to use the freezer as well here

Comment on lines +142 to +156
async def test_water_hammer_duration_handles_invalid_data(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_yardian_client: object,
) -> None:
"""Water hammer duration converts integers and ignores invalid data."""
coordinator = await _prepare_coordinator(hass, mock_config_entry)

assert _water_hammer_duration_value(coordinator) == 2

_set_oper_info(coordinator, {"iWaterHammerDuration": "oops"})
assert _water_hammer_duration_value(coordinator) is None

_set_oper_info(coordinator, {"iWaterHammerDuration": None})
assert _water_hammer_duration_value(coordinator) is None
Copy link
Member

Choose a reason for hiding this comment

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

So to repeat my previous question, is this a real life scenario or is this just being cautious?

@home-assistant home-assistant bot marked this pull request as draft November 4, 2025 05:34
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.

3 participants