-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add rainbird rain delay number entity, deprecating the sensor and service #86208
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd51fd0
Add the rain delay number entity, deprecating the sensor and service
allenporter 027d111
Create issue when service is called
allenporter d7892ac
Fix entity naming and return entity ids in the repair issue
allenporter 93ce272
Fix translation strings
allenporter 7624269
Apply suggestions from code review
allenporter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """The number platform for rainbird.""" | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from homeassistant.components.number import NumberEntity | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import UnitOfTime | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
| from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
|
||
| from .const import DOMAIN | ||
| from .coordinator import RainbirdUpdateCoordinator | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| config_entry: ConfigEntry, | ||
| async_add_entities: AddEntitiesCallback, | ||
| ) -> None: | ||
| """Set up entry for a Rain Bird number platform.""" | ||
| async_add_entities( | ||
| [ | ||
| RainDelayNumber( | ||
| hass.data[DOMAIN][config_entry.entry_id], | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| class RainDelayNumber(CoordinatorEntity[RainbirdUpdateCoordinator], NumberEntity): | ||
| """A number implemnetaiton for the rain delay.""" | ||
|
|
||
| _attr_native_min_value = 0 | ||
| _attr_native_max_value = 14 | ||
| _attr_native_step = 1 | ||
| _attr_native_unit_of_measurement = UnitOfTime.DAYS | ||
| _attr_icon = "mdi:water-off" | ||
| _attr_name = "Rain delay" | ||
| _attr_has_entity_name = True | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: RainbirdUpdateCoordinator, | ||
| ) -> None: | ||
| """Initialize the Rain Bird sensor.""" | ||
| super().__init__(coordinator) | ||
| self._attr_unique_id = f"{coordinator.serial_number}-rain-delay" | ||
| self._attr_device_info = coordinator.device_info | ||
|
|
||
| @property | ||
| def native_value(self) -> float | None: | ||
| """Return the value reported by the sensor.""" | ||
| return self.coordinator.data.rain_delay | ||
|
|
||
| async def async_set_native_value(self, value: float) -> None: | ||
| """Update the current value.""" | ||
| await self.coordinator.controller.set_rain_delay(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """Tests for rainbird number platform.""" | ||
|
|
||
|
|
||
| import pytest | ||
|
|
||
| from homeassistant.components import number | ||
| from homeassistant.components.rainbird import DOMAIN | ||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import ATTR_ENTITY_ID, Platform | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import device_registry as dr | ||
|
|
||
| from .conftest import ( | ||
| ACK_ECHO, | ||
| RAIN_DELAY, | ||
| RAIN_DELAY_OFF, | ||
| SERIAL_NUMBER, | ||
| ComponentSetup, | ||
| mock_response, | ||
| ) | ||
|
|
||
| from tests.test_util.aiohttp import AiohttpClientMocker | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def platforms() -> list[str]: | ||
| """Fixture to specify platforms to test.""" | ||
| return [Platform.NUMBER] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "rain_delay_response,expected_state", | ||
| [(RAIN_DELAY, "16"), (RAIN_DELAY_OFF, "0")], | ||
| ) | ||
| async def test_number_values( | ||
| hass: HomeAssistant, | ||
| setup_integration: ComponentSetup, | ||
| expected_state: str, | ||
| ) -> None: | ||
| """Test sensor platform.""" | ||
|
|
||
| assert await setup_integration() | ||
|
|
||
| raindelay = hass.states.get("number.rain_bird_controller_rain_delay") | ||
| assert raindelay is not None | ||
| assert raindelay.state == expected_state | ||
| assert raindelay.attributes == { | ||
| "friendly_name": "Rain Bird Controller Rain delay", | ||
| "icon": "mdi:water-off", | ||
| "min": 0, | ||
| "max": 14, | ||
| "mode": "auto", | ||
| "step": 1, | ||
| "unit_of_measurement": "d", | ||
| } | ||
|
|
||
|
|
||
| async def test_set_value( | ||
| hass: HomeAssistant, | ||
| setup_integration: ComponentSetup, | ||
| aioclient_mock: AiohttpClientMocker, | ||
| responses: list[str], | ||
| config_entry: ConfigEntry, | ||
| ) -> None: | ||
| """Test setting the rain delay number.""" | ||
|
|
||
| assert await setup_integration() | ||
|
|
||
| device_registry = dr.async_get(hass) | ||
| device = device_registry.async_get_device({(DOMAIN, SERIAL_NUMBER)}) | ||
| assert device | ||
| assert device.name == "Rain Bird Controller" | ||
|
|
||
| aioclient_mock.mock_calls.clear() | ||
| responses.append(mock_response(ACK_ECHO)) | ||
|
|
||
| await hass.services.async_call( | ||
| number.DOMAIN, | ||
| number.SERVICE_SET_VALUE, | ||
| { | ||
| ATTR_ENTITY_ID: "number.rain_bird_controller_rain_delay", | ||
| number.ATTR_VALUE: 3, | ||
| }, | ||
| blocking=True, | ||
| ) | ||
|
|
||
| assert len(aioclient_mock.mock_calls) == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.