-
-
Notifications
You must be signed in to change notification settings - Fork 36.5k
add date and time service to bosch_alarm #142243
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 all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f24a18b
add date and time service
sanjay900 6a7718e
update quality scale
sanjay900 86b70d6
add changes from review
sanjay900 d387784
Merge branch 'dev' into bosch_alarm_services
sanjay900 fb85266
fix issues after merge
sanjay900 d0681d1
fix icons
sanjay900 b3eff09
Merge remote-tracking branch 'upstream' into bosch_alarm_services
sanjay900 a3dce82
Merge branch 'dev' into bosch_alarm_services
sanjay900 47d1d32
apply changes from review
sanjay900 43fa736
remove list from service schema
sanjay900 ea7c1da
update quality scale
sanjay900 28f2dd0
update strings
sanjay900 e4d58d2
Merge remote-tracking branch 'upstream/dev' into bosch_alarm_services
sanjay900 d9f48d5
Update homeassistant/components/bosch_alarm/services.py
sanjay900 84bb154
apply changes from review
sanjay900 6eed9f2
apply changes from review
sanjay900 fb6b31c
Update tests/components/bosch_alarm/test_services.py
sanjay900 895db83
validate exception messages
sanjay900 f59a9e1
Merge branch 'bosch_alarm_services' of github.com:sanjay900/core into…
sanjay900 a291920
use schema to validate service call
sanjay900 6b65937
update docstring
sanjay900 9791f49
update error message
sanjay900 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
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 |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| """Constants for the Bosch Alarm integration.""" | ||
|
|
||
| DOMAIN = "bosch_alarm" | ||
| HISTORY_ATTR = "history" | ||
| ATTR_HISTORY = "history" | ||
| CONF_INSTALLER_CODE = "installer_code" | ||
| CONF_USER_CODE = "user_code" | ||
| ATTR_DATETIME = "datetime" | ||
| SERVICE_SET_DATE_TIME = "set_date_time" | ||
| ATTR_CONFIG_ENTRY_ID = "config_entry_id" |
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 |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| { | ||
| "services": { | ||
| "set_date_time": { | ||
| "service": "mdi:clock-edit" | ||
| } | ||
| }, | ||
| "entity": { | ||
| "sensor": { | ||
| "alarms_gas": { | ||
|
|
||
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,76 @@ | ||
| """Services for the bosch_alarm integration.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import datetime as dt | ||
| from typing import Any | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.config_entries import ConfigEntryState | ||
| from homeassistant.core import HomeAssistant, ServiceCall | ||
| from homeassistant.exceptions import HomeAssistantError, ServiceValidationError | ||
| from homeassistant.helpers import config_validation as cv | ||
| from homeassistant.util import dt as dt_util | ||
|
|
||
| from .const import ATTR_CONFIG_ENTRY_ID, ATTR_DATETIME, DOMAIN, SERVICE_SET_DATE_TIME | ||
| from .types import BoschAlarmConfigEntry | ||
|
|
||
|
|
||
| def validate_datetime(value: Any) -> dt.datetime: | ||
| """Validate that a provided datetime is supported on a bosch alarm panel.""" | ||
| date_val = cv.datetime(value) | ||
| if date_val.year < 2010: | ||
| raise vol.RangeInvalid("datetime must be after 2009") | ||
|
|
||
| if date_val.year > 2037: | ||
| raise vol.RangeInvalid("datetime must be before 2038") | ||
|
|
||
| return date_val | ||
|
|
||
|
|
||
| SET_DATE_TIME_SCHEMA = vol.Schema( | ||
| { | ||
| vol.Required(ATTR_CONFIG_ENTRY_ID): cv.string, | ||
| vol.Optional(ATTR_DATETIME): validate_datetime, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def setup_services(hass: HomeAssistant) -> None: | ||
| """Set up the services for the bosch alarm integration.""" | ||
|
|
||
| async def async_set_panel_date(call: ServiceCall) -> None: | ||
| """Set the date and time on a bosch alarm panel.""" | ||
| config_entry: BoschAlarmConfigEntry | None | ||
| value: dt.datetime = call.data.get(ATTR_DATETIME, dt_util.now()) | ||
| entry_id = call.data[ATTR_CONFIG_ENTRY_ID] | ||
| if not (config_entry := hass.config_entries.async_get_entry(entry_id)): | ||
| raise ServiceValidationError( | ||
| translation_domain=DOMAIN, | ||
| translation_key="integration_not_found", | ||
| translation_placeholders={"target": entry_id}, | ||
| ) | ||
| if config_entry.state is not ConfigEntryState.LOADED: | ||
| raise HomeAssistantError( | ||
| translation_domain=DOMAIN, | ||
| translation_key="not_loaded", | ||
| translation_placeholders={"target": config_entry.title}, | ||
| ) | ||
| panel = config_entry.runtime_data | ||
| try: | ||
| await panel.set_panel_date(value) | ||
| except asyncio.InvalidStateError as err: | ||
| raise HomeAssistantError( | ||
| translation_domain=DOMAIN, | ||
| translation_key="connection_error", | ||
| translation_placeholders={"target": config_entry.title}, | ||
| ) from err | ||
|
|
||
| hass.services.async_register( | ||
| DOMAIN, | ||
| SERVICE_SET_DATE_TIME, | ||
| async_set_panel_date, | ||
| schema=SET_DATE_TIME_SCHEMA, | ||
| ) | ||
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,12 @@ | ||
| set_date_time: | ||
| fields: | ||
| config_entry_id: | ||
| required: true | ||
| selector: | ||
| config_entry: | ||
| integration: bosch_alarm | ||
| datetime: | ||
| required: false | ||
| example: "2025-05-10 00:00:00" | ||
| selector: | ||
| datetime: |
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,7 @@ | ||
| """Types for the Bosch Alarm integration.""" | ||
|
|
||
| from bosch_alarm_mode2 import Panel | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
|
|
||
| type BoschAlarmConfigEntry = ConfigEntry[Panel] |
Oops, something went wrong.
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.