Skip to content

Commit

Permalink
Change copy schedule direction (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Oct 15, 2024
1 parent 61210bb commit 0bb603b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
34 changes: 18 additions & 16 deletions custom_components/homematicip_local/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Mapping
from datetime import datetime, timedelta
import logging
from typing import Any, Final
from typing import Any, Final, cast

from hahomematic.const import HmPlatform
from hahomematic.platforms.custom import (
Expand Down Expand Up @@ -72,8 +72,8 @@
ATTR_PROFILE_DATA: Final = "profile_data"
ATTR_SIMPLE_PROFILE_DATA: Final = "simple_profile_data"
ATTR_SIMPLE_WEEKDAY_LIST: Final = "simple_weekday_list"
ATTR_SOURCE_ENTITY_ID: Final = "source_entity_id"
ATTR_SOURCE_PROFILE: Final = "source_profile"
ATTR_TARGET_ENTITY_ID: Final = "target_entity_id"
ATTR_TARGET_PROFILE: Final = "target_profile"
ATTR_TEMPERATURE_OFFSET: Final = "temperature_offset"
ATTR_WEEKDAY: Final = "weekday"
Expand Down Expand Up @@ -168,15 +168,15 @@ def async_add_climate(hm_entities: tuple[BaseClimateEntity, ...]) -> None:
platform.async_register_entity_service(
name=SERVICE_COPY_SCHEDULE,
schema={
vol.Required(ATTR_TARGET_ENTITY_ID): cv.string,
vol.Required(ATTR_SOURCE_ENTITY_ID): cv.string,
},
func="async_copy_schedule",
)

platform.async_register_entity_service(
name=SERVICE_COPY_SCHEDULE_PROFILE,
schema={
vol.Optional(ATTR_TARGET_ENTITY_ID): cv.string,
vol.Optional(ATTR_SOURCE_ENTITY_ID): cv.string,
vol.Required(ATTR_SOURCE_PROFILE): cv.string,
vol.Required(ATTR_TARGET_PROFILE): cv.string,
},
Expand Down Expand Up @@ -439,26 +439,28 @@ async def async_disable_away_mode(self) -> None:
"""Disable the away mode on thermostat."""
await self._hm_entity.disable_away_mode()

async def async_copy_schedule(self, target_entity_id: str) -> None:
"""Copy a schedule from this entity to another."""
if target_climate_entity := self._hm_entity.device.central.get_entity_by_custom_id(
custom_id=target_entity_id
async def async_copy_schedule(self, source_entity_id: str) -> None:
"""Copy a schedule from this entity to another."""
if source_climate_entity := cast(
BaseClimateEntity,
self._hm_entity.device.central.get_entity_by_custom_id(custom_id=source_entity_id),
):
await self._hm_entity.copy_schedule(target_climate_entity=target_climate_entity)
await source_climate_entity.copy_schedule(target_climate_entity=self._hm_entity)

async def async_copy_schedule_profile(
self, source_profile: str, target_profile: str, target_entity_id: str | None = None
self, source_profile: str, target_profile: str, source_entity_id: str | None = None
) -> None:
"""Copy a schedule profile."""
if target_entity_id and (
target_climate_entity := self._hm_entity.device.central.get_entity_by_custom_id(
custom_id=target_entity_id
"""Copy a schedule profile."""
if source_entity_id and (
source_climate_entity := cast(
BaseClimateEntity,
self._hm_entity.device.central.get_entity_by_custom_id(custom_id=source_entity_id),
)
):
await self._hm_entity.copy_schedule_profile(
await source_climate_entity.copy_schedule_profile(
source_profile=source_profile,
target_profile=target_profile,
target_climate_entity=target_climate_entity,
target_climate_entity=self._hm_entity,
)
else:
await self._hm_entity.copy_schedule_profile(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/homematicip_local/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ copy_schedule:
domain: climate
integration: homematicip_local
fields:
target_entity_id:
source_entity_id:
required: true
selector:
entity:
Expand All @@ -27,7 +27,7 @@ copy_schedule_profile:
domain: climate
integration: homematicip_local
fields:
target_entity_id:
source_entity_id:
required: false
selector:
entity:
Expand Down
14 changes: 7 additions & 7 deletions custom_components/homematicip_local/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,24 +651,24 @@
"copy_schedule": {
"description": "Copy a schedule to another device",
"fields": {
"target_entity_id": {
"description": "Climate entity to copy schedule to",
"name": "Target entity"
"source_entity_id": {
"description": "Climate entity to copy the schedule from",
"name": "Source entity"
}
},
"name": "Copy schedule"
},
"copy_schedule_profile": {
"description": "Copy a schedule profile to another device",
"fields": {
"source_entity_id": {
"description": "Climate entity to copy the schedule from",
"name": "Source entity"
},
"source_profile": {
"description": "Source profile to copy from",
"name": "Source profile"
},
"target_entity_id": {
"description": "Climate entity to copy schedule to",
"name": "Target entity"
},
"target_profile": {
"description": "Target profile to copy to",
"name": "Target profile"
Expand Down
14 changes: 7 additions & 7 deletions custom_components/homematicip_local/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -655,24 +655,24 @@
"copy_schedule": {
"description": "Kopiert einen Zeitplan zu einem anderen Gerät",
"fields": {
"target_entity_id": {
"description": "Klimaentität, in die der Zeitplan kopiert werden soll",
"name": "Zielentität"
"source_entity_id": {
"description": "Klimaentität, von der der Zeitplan kopiert werden soll",
"name": "Quellentität"
}
},
"name": "Zeitplan kopieren"
},
"copy_schedule_profile": {
"description": "Kopiert einen Zeitplan auf ein anderes Gerät",
"fields": {
"source_entity_id": {
"description": "Klimaentität, von der der Zeitplan kopiert werden soll",
"name": "Quellentität"
},
"source_profile": {
"description": "Quellprofil zum Kopieren",
"name": "Quellprofil"
},
"target_entity_id": {
"description": "Klimaentität, in die der Zeitplan kopiert werden soll",
"name": "Zielentität"
},
"target_profile": {
"description": "Zielprofil zum Kopieren",
"name": "Zielprofil"
Expand Down
14 changes: 7 additions & 7 deletions custom_components/homematicip_local/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,24 +651,24 @@
"copy_schedule": {
"description": "Copy a schedule to another device",
"fields": {
"target_entity_id": {
"description": "Climate entity to copy schedule to",
"name": "Target entity"
"source_entity_id": {
"description": "Climate entity to copy the schedule from",
"name": "Source entity"
}
},
"name": "Copy schedule"
},
"copy_schedule_profile": {
"description": "Copy a schedule profile to another device",
"fields": {
"source_entity_id": {
"description": "Climate entity to copy the schedule from",
"name": "Source entity"
},
"source_profile": {
"description": "Source profile to copy from",
"name": "Source profile"
},
"target_entity_id": {
"description": "Climate entity to copy schedule to",
"name": "Target entity"
},
"target_profile": {
"description": "Target profile to copy to",
"name": "Target profile"
Expand Down

0 comments on commit 0bb603b

Please sign in to comment.