From c17170c507f015880c79e41219a8c48d60334068 Mon Sep 17 00:00:00 2001 From: Michael Kirsch Date: Sun, 18 Jul 2021 21:12:34 +0200 Subject: [PATCH 01/31] add xy and hs as alternative color modes --- custom_components/adaptive_lighting/switch.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index cfe073c1..d4f49c8c 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -40,6 +40,8 @@ from homeassistant.components.light import ( is_on, COLOR_MODE_RGB, COLOR_MODE_RGBW, + COLOR_MODE_HS, + COLOR_MODE_XY, COLOR_MODE_COLOR_TEMP, COLOR_MODE_BRIGHTNESS, ATTR_SUPPORTED_COLOR_MODES, @@ -395,6 +397,12 @@ def _supported_features(hass: HomeAssistant, light: str): if COLOR_MODE_RGBW in supported_color_modes: supported.add("color") supported.add("brightness") # see above url + if COLOR_MODE_XY in supported_color_modes: + supported.add("color") + supported.add("brightness") # see above url + if COLOR_MODE_HS in supported_color_modes: + supported.add("color") + supported.add("brightness") # see above url if COLOR_MODE_COLOR_TEMP in supported_color_modes: supported.add("color_temp") supported.add("brightness") # see above url From 458cd45964b43e10425ba68bd3d01532540d89fa Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sun, 1 Aug 2021 11:37:29 +0200 Subject: [PATCH 02/31] add Maintainers section --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 4df681b1..ffe75355 100644 --- a/README.md +++ b/README.md @@ -186,3 +186,9 @@ These graphs were generated using the values calculated by the Adaptive Lighting ##### Brightness: ![cl_brightness|690x130](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/5/8/58ebd994b62a8b1abfb3497a5288d923ff4e2330.PNG) + +# Maintainers + +- @basnijholt +- @RubenKelevra + From 2001a737ff593f294cf5fc9b9aeb255357812351 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 16:41:16 +0200 Subject: [PATCH 03/31] Create config.yml Source: https://github.com/ipfs/go-ipfs/blob/master/.github/config.yml --- .github/config.yml | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/config.yml diff --git a/.github/config.yml b/.github/config.yml new file mode 100644 index 00000000..915efced --- /dev/null +++ b/.github/config.yml @@ -0,0 +1,64 @@ +# Configuration for welcome - https://github.com/behaviorbot/welcome + +# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome +# Comment to be posted to on first time issues +newIssueWelcomeComment: > + Thank you for submitting your first issue to this repository! A maintainer + will be here shortly to triage and review. + + In the meantime, please double-check that you have provided all the + necessary information to make this process easy! Any information that can + help save additional round trips is useful! We currently aim to give + initial feedback within **two business days**. If this does not happen, feel + free to leave a comment. + + Please keep an eye on how this issue will be labeled, as labels give an + overview of priorities, assignments and additional actions requested by the + maintainers: + + - "Priority" labels will show how urgent this is for the team. + - "Status" labels will show if this is ready to be worked on, blocked, or in progress. + - "Need" labels will indicate if additional input or analysis is required. + + Finally, remember to use [the discussion tab](https://github.com/basnijholt/adaptive-lighting/discussions) if you just need general + support. + +# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome +# Comment to be posted to on PRs from first time contributors in your repository +newPRWelcomeComment: > + Thank you for submitting this PR! + + A maintainer will be here shortly to review it. + + We are super grateful! Help us by making sure that: + + * The context for this PR is clear, with relevant discussion, decisions + and stakeholders linked/mentioned. + + * Your contribution itself is clear (code comments, self-review for the + rest) and in its best form. + + Getting other community members to do a review would be great help too on + complex PRs. If you are unsure about something, just leave us a comment. + + Next steps: + + * A maintainer will triage and assign priority to this PR, commenting on + any missing things and potentially assigning a reviewer for high + priority items. + + * The PR gets reviews, discussed and approvals as needed. + + * The PR is merged by maintainers when it has been approved and comments addressed. + + We currently aim to provide initial feedback/triaging within **two business + days**. Please keep an eye on any labelling actions, as these will indicate + priorities and status of your contribution. + + We are very grateful for your contribution! + + +# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge +# Comment to be posted to on pull requests merged by a first time user +# Currently disabled +#firstPRMergeComment: "" From e9164e7f63eb17b9090f3b54c7600f2249f6dd73 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 16:43:09 +0200 Subject: [PATCH 04/31] Create auto-comment.yml Source: https://github.com/ipfs/go-ipfs/blob/master/.github/auto-comment.yml --- .github/auto-comment.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/auto-comment.yml diff --git a/.github/auto-comment.yml b/.github/auto-comment.yml new file mode 100644 index 00000000..c1272240 --- /dev/null +++ b/.github/auto-comment.yml @@ -0,0 +1,6 @@ +# Comment to a new issue. +# Disabled +# issueOpened: "" + +# Disabled +# pullRequestOpened: "" From cd5abe80a4fb47ca3a716df26703344b77e24819 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 16:54:42 +0200 Subject: [PATCH 05/31] Create bug-report.md Source: https://github.com/ipfs/go-ipfs/blob/08e058427f760d8d171a6666d955ca7146cd352a/.github/ISSUE_TEMPLATE/bug-report.md --- .github/ISSUE_TEMPLATE/bug-report.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 00000000..c5bcb3a4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,17 @@ +--- +name: 'Bug Report' +about: 'Report a bug in adaptive-lighting.' +labels: kind/bug, need/triage +--- + +#### Version information: + + +#### Description: + From d9639e0dccd8d9a656ea1e20aac5965db7a28661 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 16:57:15 +0200 Subject: [PATCH 06/31] Create doc.md Source: https://github.com/ipfs/go-ipfs/blob/08e058427f760d8d171a6666d955ca7146cd352a/.github/ISSUE_TEMPLATE/doc.md --- .github/ISSUE_TEMPLATE/doc.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/doc.md diff --git a/.github/ISSUE_TEMPLATE/doc.md b/.github/ISSUE_TEMPLATE/doc.md new file mode 100644 index 00000000..98c9a008 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/doc.md @@ -0,0 +1,13 @@ +--- +name: 'Documentation Issue' +about: 'Report missing, erroneous docs, broken links or propose new docs' +labels: kind/docs_issue, need/triage +--- + +#### Location + + + +#### Description + + From aeca253ade1074fcad58f02bfbff6feb016505d6 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 16:58:09 +0200 Subject: [PATCH 07/31] Create enhancement.md --- .github/ISSUE_TEMPLATE/enhancement.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/enhancement.md diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md new file mode 100644 index 00000000..71501f54 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/enhancement.md @@ -0,0 +1,6 @@ +--- +name: 'Enhancement' +about: 'Suggest an improvement to an existing feature.' +labels: kind/enhancement need/triage +--- + From d083af2149241413bf868a9fa10c32f550127738 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 16:58:52 +0200 Subject: [PATCH 08/31] Create feature.md --- .github/ISSUE_TEMPLATE/feature.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature.md diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md new file mode 100644 index 00000000..c4b787df --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -0,0 +1,5 @@ +--- +name: 'Feature' +about: 'Suggest a new feature' +labels: kind/feature, need/triage +--- From 4edd1191d986149d97351042911a11b62240bce6 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 17:02:39 +0200 Subject: [PATCH 09/31] Create config.yml --- .github/ISSUE_TEMPLATE/config.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..c4eeda14 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,14 @@ +blank_issues_enabled: false +contact_links: + - name: Getting Help on adaptive-lighting + url: https://github.com/basnijholt/adaptive-lighting/discussions/categories/q-a + about: Q&A section of the discussion tab + - name: Share your idea + url: https://github.com/basnijholt/adaptive-lighting/discussions/categories/ideas + about: And discuss it with the community + - name: General discussions about this component + url: https://github.com/basnijholt/adaptive-lighting/discussions/categories/general + about: General discussions about this component + - name: Share your setup with adaptive-lighting + url: https://github.com/basnijholt/adaptive-lighting/discussions/categories/show-and-tell + about: Or see what other people do with this component From a24e8d16b0ad0523fe7949e11b3fb29b81836c63 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 17:05:13 +0200 Subject: [PATCH 10/31] ISSUE_TEMPLATE/enhancement.md: add missing comma --- .github/ISSUE_TEMPLATE/enhancement.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md index 71501f54..fcd16fc6 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.md +++ b/.github/ISSUE_TEMPLATE/enhancement.md @@ -1,6 +1,6 @@ --- name: 'Enhancement' about: 'Suggest an improvement to an existing feature.' -labels: kind/enhancement need/triage +labels: kind/enhancement, need/triage --- From f7afdb1ba2da6d1e34869d6fc17ad54c5a5e6636 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 17:08:40 +0200 Subject: [PATCH 11/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffe75355..e311694e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![](https://github.com/home-assistant/brands/raw/b4a168b9af282ef916e120d31091ecd5e3c35e66/core_integrations/adaptive_lighting/icon.png) _Try out this code by adding https://github.com/basnijholt/adaptive-lighting to your custom repos in [HACS (Home Assistant Community Store)](https://hacs.xyz/) and install it!_ -*This `custom_component` is also being added to `core`, see [this PR](https://github.com/home-assistant/core/pull/40626), although it might take months before it makes it in.* + The `adaptive_lighting` platform changes the settings of your lights throughout the day. It uses the position of the sun to calculate the color temperature and brightness that is most fitting for that time of the day. From 449de6510ff006207c9cd1a8d2355bd7fc50df5d Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 17:47:20 +0200 Subject: [PATCH 12/31] add validation workflow for HACS --- .github/workflows/validate.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/validate.yml diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 00000000..fc1b5f91 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,17 @@ +name: Validate + +on: + push: + pull_request: + schedule: + - cron: "0 0 * * *" + +jobs: + validate: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v2" + - name: HACS validation + uses: "hacs/action@main" + with: + category: "integration" From 523ddb17d6c9383feaf55c57039902ac02e7ee84 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 17:48:31 +0200 Subject: [PATCH 13/31] add hassfest validation --- .github/workflows/hassfest.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/hassfest.yaml diff --git a/.github/workflows/hassfest.yaml b/.github/workflows/hassfest.yaml new file mode 100644 index 00000000..18c7d193 --- /dev/null +++ b/.github/workflows/hassfest.yaml @@ -0,0 +1,14 @@ +name: Validate with hassfest + +on: + push: + pull_request: + schedule: + - cron: "0 0 * * *" + +jobs: + validate: + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v2" + - uses: home-assistant/actions/hassfest@master From 038e7c8a32a2f0a689bc92e02bfb97d51ac3751c Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 18:06:38 +0200 Subject: [PATCH 14/31] manifest.json: fix informations/add missing ones - fix documentation link - add issue_tracker link - add iot_class - fix version --- custom_components/adaptive_lighting/manifest.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index ee4c828b..b7716d87 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -1,10 +1,12 @@ { "domain": "adaptive_lighting", "name": "Adaptive Lighting", - "documentation": "https://www.home-assistant.io/integrations/adaptive_lighting", + "documentation": "https://github.com/basnijholt/adaptive-lighting#readme", + "issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues", "config_flow": true, "dependencies": [], "codeowners": ["@basnijholt"], - "version": "1.0.0", - "requirements": [] + "version": "1.0.13", + "requirements": [], + "iot_class": "calculated" } From 995ecb4ebf9543ae469bb68d02af2966aa7a47b3 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sun, 1 Aug 2021 22:14:36 +0200 Subject: [PATCH 15/31] update code owners in manifest - fix formatting - update version --- custom_components/adaptive_lighting/manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index b7716d87..d4f9a091 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -2,11 +2,11 @@ "domain": "adaptive_lighting", "name": "Adaptive Lighting", "documentation": "https://github.com/basnijholt/adaptive-lighting#readme", - "issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues", + "issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues", "config_flow": true, "dependencies": [], - "codeowners": ["@basnijholt"], - "version": "1.0.13", + "codeowners": ["@basnijholt", "@RubenKelevra"], + "version": "1.0.14", "requirements": [], "iot_class": "calculated" } From 64e48dfd542645832e870493fdd4047645536c50 Mon Sep 17 00:00:00 2001 From: Mike Roberts Date: Thu, 26 Aug 2021 10:15:34 -0700 Subject: [PATCH 16/31] calculate light settings at end of transition period --- custom_components/adaptive_lighting/switch.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index d4f49c8c..c2603f06 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -557,9 +557,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._prefer_rgb_color = data[CONF_PREFER_RGB_COLOR] self._separate_turn_on_commands = data[CONF_SEPARATE_TURN_ON_COMMANDS] self._take_over_control = data[CONF_TAKE_OVER_CONTROL] - self._transition = min( - data[CONF_TRANSITION], self._interval.total_seconds() // 2 - ) + self._transition = data[CONF_TRANSITION] _loc = get_astral_location(self.hass) if isinstance(_loc, tuple): # Astral v2.2 @@ -582,6 +580,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): sunset_offset=data[CONF_SUNSET_OFFSET], sunset_time=data[CONF_SUNSET_TIME], time_zone=self.hass.config.time_zone, + transition=data[CONF_TRANSITION], ) # Set other attributes @@ -744,7 +743,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): async def _async_update_at_interval(self, now=None) -> None: await self._update_attrs_and_maybe_adapt_lights( - force=False, context=self.create_context("interval") + transition=self._transition, force=False, context=self.create_context("interval") ) async def _adapt_light( @@ -857,7 +856,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): ) assert self.is_on self._settings = self._sun_light_settings.get_settings( - self.sleep_mode_switch.is_on + self.sleep_mode_switch.is_on, transition ) self.async_write_ha_state() if lights is None: @@ -1043,6 +1042,7 @@ class SunLightSettings: sunset_offset: Optional[datetime.timedelta] sunset_time: Optional[datetime.time] time_zone: datetime.tzinfo + transition: int def get_sun_events(self, date: datetime.datetime) -> Dict[str, float]: """Get the four sun event's timestamps at 'date'.""" @@ -1113,11 +1113,13 @@ class SunLightSettings: i_now = bisect.bisect([ts for _, ts in events], now.timestamp()) return events[i_now - 1 : i_now + 1] - def calc_percent(self) -> float: + def calc_percent(self, transition: int) -> float: """Calculate the position of the sun in %.""" now = dt_util.utcnow() - now_ts = now.timestamp() - today = self.relevant_events(now) + + target_time = now + timedelta(seconds=transition) + target_ts = target_time.timestamp() + today = self.relevant_events(target_time) (_, prev_ts), (next_event, next_ts) = today h, x = ( # pylint: disable=invalid-name (prev_ts, next_ts) @@ -1125,7 +1127,7 @@ class SunLightSettings: else (next_ts, prev_ts) ) k = 1 if next_event in (SUN_EVENT_SUNSET, SUN_EVENT_NOON) else -1 - percentage = (0 - k) * ((now_ts - h) / (h - x)) ** 2 + k + percentage = (0 - k) * ((target_ts - h) / (h - x)) ** 2 + k return percentage def calc_brightness_pct(self, percent: float, is_sleep: bool) -> float: @@ -1148,13 +1150,13 @@ class SunLightSettings: return self.min_color_temp def get_settings( - self, is_sleep + self, is_sleep, transition ) -> Dict[str, Union[float, Tuple[float, float], Tuple[float, float, float]]]: """Get all light settings. Calculating all values takes <0.5ms. """ - percent = self.calc_percent() + percent = self.calc_percent(transition) if transition is not None else self.calc_percent(0) brightness_pct = self.calc_brightness_pct(percent, is_sleep) color_temp_kelvin = self.calc_color_temp_kelvin(percent, is_sleep) color_temp_mired: float = color_temperature_kelvin_to_mired(color_temp_kelvin) From 7581c8bf82493abfb52e8a46c8f253aab517d470 Mon Sep 17 00:00:00 2001 From: "Michael \"Chishm\" Chisholm" Date: Wed, 8 Sep 2021 13:27:55 +1000 Subject: [PATCH 17/31] Associate contexts with causing events/services via parent_id --- custom_components/adaptive_lighting/switch.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index d4f49c8c..2cf6a597 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -177,12 +177,17 @@ def _short_hash(string: str, length: int = 4) -> str: return hashlib.sha1(string.encode("UTF-8")).hexdigest()[:length] -def create_context(name: str, which: str, index: int) -> Context: +def create_context( + name: str, which: str, index: int, parent: Optional[Context] = None +) -> Context: """Create a context that can identify this integration.""" # Use a hash for the name because otherwise the context might become # too long (max len == 36) to fit in the database. name_hash = _short_hash(name) - return Context(id=f"{_DOMAIN_SHORT}_{name_hash}_{which}_{index}") + parent_id = parent.id if parent else None + return Context( + id=f"{_DOMAIN_SHORT}_{name_hash}_{which}_{index}", parent_id=parent_id + ) def is_our_context(context: Optional[Context]) -> bool: @@ -228,6 +233,7 @@ async def handle_apply(switch: AdaptiveSwitch, service_call: ServiceCall): data[ATTR_ADAPT_COLOR], data[CONF_PREFER_RGB_COLOR], force=True, + context=switch.create_context("service", parent=service_call.context), ) @@ -254,7 +260,7 @@ async def handle_set_manual_control(switch: AdaptiveSwitch, service_call: Servic all_lights, transition=switch._initial_transition, force=True, - context=switch.create_context("service"), + context=switch.create_context("service", parent=service_call.context), ) @@ -701,7 +707,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): ] return dict(self._settings, manual_control=manual_control) - def create_context(self, which: str = "default") -> Context: + def create_context( + self, which: str = "default", parent: Optional[Context] = None + ) -> Context: """Create a context that identifies this Adaptive Lighting instance.""" # Right now the highest number of each context_id it can create is # 'adapt_lgt_XXXX_turn_on_9999999999999' @@ -711,7 +719,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): # 'adapt_lgt_XXXX_light_event_999999999' # 'adapt_lgt_XXXX_service_9999999999999' # So 100 million calls before we run into the 36 chars limit. - context = create_context(self._name, which, self._context_cnt) + context = create_context(self._name, which, self._context_cnt, parent=parent) self._context_cnt += 1 return context @@ -915,7 +923,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): await self._update_attrs_and_maybe_adapt_lights( transition=self._initial_transition, force=True, - context=self.create_context("sleep"), + context=self.create_context("sleep", parent=event.context), ) async def _light_event(self, event: Event) -> None: @@ -956,7 +964,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): lights=[entity_id], transition=self._initial_transition, force=True, - context=self.create_context("light_event"), + context=self.create_context("light_event", parent=event.context), ) elif ( old_state is not None From fa10d95305338e0dc09fe80ac71cc8d382fc2518 Mon Sep 17 00:00:00 2001 From: Avi Miller Date: Thu, 16 Sep 2021 14:15:36 +1000 Subject: [PATCH 18/31] Make the transition time to/from sleep mode configurable Signed-off-by: Avi Miller --- custom_components/adaptive_lighting/const.py | 2 ++ custom_components/adaptive_lighting/strings.json | 3 ++- custom_components/adaptive_lighting/switch.py | 4 +++- custom_components/adaptive_lighting/translations/en.json | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index e1f2e3cb..b182ed82 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -17,6 +17,7 @@ CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES = ( False, ) CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION = "initial_transition", 1 +CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION = "sleep_transition", 1 CONF_INTERVAL, DEFAULT_INTERVAL = "interval", 90 CONF_MAX_BRIGHTNESS, DEFAULT_MAX_BRIGHTNESS = "max_brightness", 100 CONF_MAX_COLOR_TEMP, DEFAULT_MAX_COLOR_TEMP = "max_color_temp", 5500 @@ -63,6 +64,7 @@ VALIDATION_TUPLES = [ (CONF_LIGHTS, DEFAULT_LIGHTS, cv.entity_ids), (CONF_PREFER_RGB_COLOR, DEFAULT_PREFER_RGB_COLOR, bool), (CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION, VALID_TRANSITION), + (CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION, VALID_TRANSITION), (CONF_TRANSITION, DEFAULT_TRANSITION, VALID_TRANSITION), (CONF_INTERVAL, DEFAULT_INTERVAL, cv.positive_int), (CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS, int_between(1, 100)), diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index 274569da..72fdcb3b 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -21,7 +21,8 @@ "description": "All settings for a Adaptive Lighting component. The option names correspond with the YAML settings. No options are shown if you have this entry defined in YAML.", "data": { "lights": "lights", - "initial_transition": "initial_transition, when lights go 'off' to 'on' or when 'sleep_state' changes", + "initial_transition": "initial_transition, when lights go 'off' to 'on'", + "sleep_transition": "sleep_transition, when 'sleep_state' changes", "interval": "interval, time between switch updates in seconds", "max_brightness": "max_brightness, in %", "max_color_temp": "max_color_temp, in Kelvin", diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 2cf6a597..0d571119 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -99,6 +99,7 @@ from .const import ( ATTR_TURN_ON_OFF_LISTENER, CONF_DETECT_NON_HA_CHANGES, CONF_INITIAL_TRANSITION, + CONF_SLEEP_TRANSITION, CONF_INTERVAL, CONF_LIGHTS, CONF_MANUAL_CONTROL, @@ -558,6 +559,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._detect_non_ha_changes = data[CONF_DETECT_NON_HA_CHANGES] self._initial_transition = data[CONF_INITIAL_TRANSITION] + self._sleep_transition = data[CONF_SLEEP_TRANSITION] self._interval = data[CONF_INTERVAL] self._only_once = data[CONF_ONLY_ONCE] self._prefer_rgb_color = data[CONF_PREFER_RGB_COLOR] @@ -921,7 +923,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): # Reset the manually controlled status when the "sleep mode" changes self.turn_on_off_listener.reset(*self._lights) await self._update_attrs_and_maybe_adapt_lights( - transition=self._initial_transition, + transition=self._sleep_transition, force=True, context=self.create_context("sleep", parent=event.context), ) diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index e66b6769..fb1c7f04 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -21,7 +21,8 @@ "description": "All settings for a Adaptive Lighting component. The option names correspond with the YAML settings. No options are shown if you have the adaptive_lighting entry defined in your YAML configuration.", "data": { "lights": "lights", - "initial_transition": "initial_transition: When lights turn 'off' to 'on' or when 'sleep_state' changes. (seconds)", + "initial_transition": "initial_transition: When lights turn 'off' to 'on'. (seconds)", + "sleep_transition": "sleep_transition: When 'sleep_state' changes. (seconds)", "interval": "interval: Time between switch updates. (seconds)", "max_brightness": "max_brightness: Highest brightness of lights during a cycle. (%)", "max_color_temp": "max_color_temp: Coldest hue of the color temperature cycle. (Kelvin)", From 4492cfe6155cd8020b3cee15cb7126e5e680fb48 Mon Sep 17 00:00:00 2001 From: Avi Miller Date: Thu, 16 Sep 2021 22:09:18 +1000 Subject: [PATCH 19/31] Update README.md to include sleep_transition Signed-off-by: Avi Miller --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e311694e..224c8bf5 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,8 @@ adaptive_lighting: | name | The name to use when displaying this switch. | False | default | string | | lights | List of light entities for Adaptive Lighting to control (may be empty). | False | list | [] | | prefer_rgb_color | Whether to use RGB color adjustment instead of native light color temperature. | False | False | boolean | -| initial_transition | How long the first transition is when the lights go from `off` to `on` (or when "sleep mode" is toggled). | False | 1 | time | +| initial_transition | How long the first transition is when the lights go from `off` to `on`. | False | 1 | time | +| sleep_transition | How long the transition is when when "sleep mode" is toggled | False | 1 | time | | transition | How long the transition is when the lights change, in seconds. | False | 45 | integer | | interval | How often to adapt the lights, in seconds. | False | 90 | integer | | min_brightness | The minimum percent of brightness to set the lights to. | False | 1 | integer | @@ -191,4 +192,3 @@ These graphs were generated using the values calculated by the Adaptive Lighting - @basnijholt - @RubenKelevra - From f3a3c1cd483ba471a3cf951b77b66592f5d42ab9 Mon Sep 17 00:00:00 2001 From: Michel Peterson Date: Wed, 22 Sep 2021 11:22:10 +0300 Subject: [PATCH 20/31] Default `lights` of the `apply` service The apply service is meant to apply the adaptive lighting parameters to a specific set of light(s). This set of lights need to be passed to the service, even though each Adaptive Lighting switch already has this list configured on itself. While having the flexibility to apply to some, it also might be useful to apply to all lights that the switch manages. This patch makes the lights paramater optional and defaults it to the lights configured on the corresponding configuration entry of the switch being called. --- custom_components/adaptive_lighting/services.yaml | 2 +- custom_components/adaptive_lighting/switch.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/services.yaml b/custom_components/adaptive_lighting/services.yaml index 10bfd2a8..8f449a77 100755 --- a/custom_components/adaptive_lighting/services.yaml +++ b/custom_components/adaptive_lighting/services.yaml @@ -5,7 +5,7 @@ apply: description: entity_id of the Adaptive Lighting switch. example: switch.adaptive_lighting_default lights: - description: entity_id(s) of lights. + description: "entity_id(s) of lights, default: lights of the switch" example: light.bedroom_ceiling transition: description: Transition of the lights. diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index ffd8bebd..be877dff 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -322,7 +322,7 @@ async def async_setup_entry( platform.async_register_entity_service( SERVICE_APPLY, { - vol.Required(CONF_LIGHTS): cv.entity_ids, + vol.Optional(CONF_LIGHTS, default=switch._lights): cv.entity_ids, # pylint: disable=protected-access vol.Optional( CONF_TRANSITION, default=switch._initial_transition, # pylint: disable=protected-access From 346dda9c6c4bc81c21252a16d92104665ae082fe Mon Sep 17 00:00:00 2001 From: Sindre Broch Date: Wed, 22 Sep 2021 21:40:21 +0200 Subject: [PATCH 21/31] Fix spelling in description to Kelvin --- custom_components/adaptive_lighting/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index fb1c7f04..cc32a722 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -27,7 +27,7 @@ "max_brightness": "max_brightness: Highest brightness of lights during a cycle. (%)", "max_color_temp": "max_color_temp: Coldest hue of the color temperature cycle. (Kelvin)", "min_brightness": "min_brightness: Lowest brightness of lights during a cycle. (%)", - "min_color_temp": "min_color_temp, Warmest hue of the color temperature cycle. (%)", + "min_color_temp": "min_color_temp, Warmest hue of the color temperature cycle. (Kelvin)", "only_once": "only_once: Only adapt the lights when turning them on.", "prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.", "separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).", From ebbf6673c1740244ee7029667af85a341cf33f7d Mon Sep 17 00:00:00 2001 From: Shulyaka Date: Fri, 24 Sep 2021 01:47:53 +0300 Subject: [PATCH 22/31] Add .gitignore from python template --- .gitignore | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b6e47617 --- /dev/null +++ b/.gitignore @@ -0,0 +1,129 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ From e2212c11448da1bcdf719f5db411687b7afc7fdf Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 29 Sep 2021 10:07:00 +0200 Subject: [PATCH 23/31] fix docs on set_manual_control --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 224c8bf5..2b4edb82 100644 --- a/README.md +++ b/README.md @@ -114,8 +114,8 @@ adaptive_lighting: | Service data attribute | Optional | Description | |------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------| | `entity_id` | no | The `entity_id` of the switch in which to (un)mark the light as being "manually controlled". | -| `lights` | no | A light (or list of lights) to apply the settings to. | -| `manual_control` | yes | Whether to mark (true) or unmark (false) the light as "manually controlled", when not specified it selects all lights in the switch. | +| `lights` | yes | entity_id(s) of lights, if not specified, all lights in the switch are selected. | +| `manual_control` | yes | Whether to add ('true') or remove ('false') the light from the 'manual_control' list, default: true | ## Automation examples From 249d6f82c8cd2b9f2ce2dd3916b879fe206b6c80 Mon Sep 17 00:00:00 2001 From: vapescherov Date: Mon, 8 Nov 2021 03:34:50 +0500 Subject: [PATCH 24/31] Allow sunsets after midnight --- custom_components/adaptive_lighting/switch.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index be877dff..6c9cd7d6 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1066,6 +1066,18 @@ class SunLightSettings: utc_time = date_time.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE).astimezone(dt_util.UTC) return utc_time + def calculate_noon_and_midnight( + sunset: datetime.datetime, sunrise: datetime.datetime + ) -> (datetime.datetime, datetime.datetime): + middle = abs(sunset - sunrise) / 2 + if sunset > sunrise: + noon = sunrise + middle + midnight = noon + timedelta(hours=12) * (1 if noon.hour < 12 else -1) + else: + midnight = sunset + middle + noon = midnight + timedelta(hours=12) * (1 if midnight.hour < 12 else -1) + return noon, midnight + location = self.astral_location sunrise = ( @@ -1089,8 +1101,7 @@ class SunLightSettings: solar_noon = location.noon(date, local=False) solar_midnight = location.midnight(date, local=False) else: - solar_noon = sunrise + (sunset - sunrise) / 2 - solar_midnight = sunset + ((sunrise + timedelta(days=1)) - sunset) / 2 + (solar_noon, solar_midnight) = calculate_noon_and_midnight(sunset, sunrise) events = [ (SUN_EVENT_SUNRISE, sunrise.timestamp()), From 65fad194539a308aab1435919fdb4c08a4a3627a Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Tue, 9 Nov 2021 01:29:56 +0100 Subject: [PATCH 25/31] add some batches stolen from https://github.com/bramstroker/homeassistant-powercalc/edit/master/README.md ;) Source: https://github.com/bramstroker/homeassistant-powercalc/edit/master/README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2b4edb82..d0dadacc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) +![Version](https://img.shields.io/github/v/release/basnijholt/adaptive-lighting) + # Adaptive Lighting component for Home Assistant ![](https://github.com/home-assistant/brands/raw/b4a168b9af282ef916e120d31091ecd5e3c35e66/core_integrations/adaptive_lighting/icon.png) From cc90c512555977dcd204d4c1a06d5e5ee1304b25 Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Sat, 13 Nov 2021 23:49:03 +1000 Subject: [PATCH 26/31] Fix default lights for adaptive_lighting.apply service --- custom_components/adaptive_lighting/switch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 6c9cd7d6..c07f8b5c 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -222,9 +222,15 @@ async def handle_apply(switch: AdaptiveSwitch, service_call: ServiceCall): """Handle the entity service apply.""" hass = switch.hass data = service_call.data - all_lights = _expand_light_groups(hass, data[CONF_LIGHTS]) + all_lights = data[CONF_LIGHTS] + if not all_lights: + all_lights = switch._lights + all_lights = _expand_light_groups(hass, all_lights) switch.turn_on_off_listener.lights.update(all_lights) - + _LOGGER.debug( + "Called 'adaptive_lighting.apply' service with '%s'", + data, + ) for light in all_lights: if data[CONF_TURN_ON_LIGHTS] or is_on(hass, light): await switch._adapt_light( # pylint: disable=protected-access @@ -322,7 +328,7 @@ async def async_setup_entry( platform.async_register_entity_service( SERVICE_APPLY, { - vol.Optional(CONF_LIGHTS, default=switch._lights): cv.entity_ids, # pylint: disable=protected-access + vol.Optional(CONF_LIGHTS, default=[]): cv.entity_ids, # pylint: disable=protected-access vol.Optional( CONF_TRANSITION, default=switch._initial_transition, # pylint: disable=protected-access From 169042ce9dcf12ba63fad2bd8946a68ff22377c8 Mon Sep 17 00:00:00 2001 From: covid10 <71146231+covid10@users.noreply.github.com> Date: Fri, 10 Dec 2021 17:14:50 +0100 Subject: [PATCH 27/31] Create nb.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Norwegian (norsk bokmål) translation --- .../adaptive_lighting/translations/nb.json | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 custom_components/adaptive_lighting/translations/nb.json diff --git a/custom_components/adaptive_lighting/translations/nb.json b/custom_components/adaptive_lighting/translations/nb.json new file mode 100644 index 00000000..fbbfafee --- /dev/null +++ b/custom_components/adaptive_lighting/translations/nb.json @@ -0,0 +1,49 @@ +{ + "title":"Adaptiv Belysning", + "config":{ + "step":{ + "user":{ + "title":"Velg et navn", + "description":"Velg et navn for denne konfigurasjonen for adaptiv belysning - hver konfigurasjon kan inneholde flere lyskilder!", + "data":{ + "name":"Navn" + } + } + }, + "abort":{ + "already_configured":"Denne enheten er allerede konfigurert!" + } + }, + "options":{ + "step":{ + "init":{ + "title":"Adaptiv Belysning Innstillinger", + "description":"Alle innstillinger for en adaptiv belysning konfigurasjon. Innstillingene er identiske med innstillingene for YAML konfigurasjon. Ingen innstillinger vises dersom du har definert adaptive_lighting i din YAML konfigurasjon.", + "data":{ + "lights":"Lys / Lyskilder", + "initial_transition":"'initial_transition': varigheten på startovergangen (i sekunder) når lysene skrus av eller på - eller når 'sleep_state' endres", + "interval":"'interval': tiden mellom oppdateringer (i sekunder)", + "max_brightness":"'max_brightness': den høyeste lysstyrken (i prosent) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", + "max_color_temp":"'max_color_temp': den høyeste fargetemperaturen (i kelvin) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", + "min_brightness":"'min_brightness': den laveste lysstyrken (i prosent) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", + "min_color_temp":"'min_color_temp': den laveste fargetemperaturen (i kelvin) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", + "only_once":"'only_once': anvend innstillingene for adaptiv belysning kun når lysene skrus av eller på", + "prefer_rgb_color":"'prefer_rgb_color': benytt rgb i stedet for fargetemperatur dersom det er mulig", + "separate_turn_on_commands":"'separate_turn_on_commands': separer kommandone i 'light.turn_on' for hver attributt (farge, lysstyrke, osv.). Dette kan være nødvendig for enkelte typer lys / lyskilder", + "sleep_brightness":"'sleep_brightness': lysstyrken på lysene (i prosent) når 'sleep_mode' (søvnmodus) er aktiv", + "sleep_color_temp":"'sleep_color_temp': fargetemperaturen på lysene (i kelvin) når 'sleep_mode' (søvnmodus) er aktiv", + "sunrise_offset":"'sunrise_offset': utligningen i tidspunktet for soloppgang - hvor lenge før (-) eller etter (+) tidspunktet solen står opp (lokalt) skal defineres som soloppgang (i sekunder - f. eks: '-1800' vil definere tidspunktet for soloppgang en halvtime tidligere enn det faktiske tidspunktet for soloppgang)", + "sunrise_time":"'sunrise_time': definer tidspunktet for soloppgang manuelt (i følgende format: TT:MM:SS - f. eks: '08:00:00' vil definere tidspunktet for soloppgang som klokken 8 på morgenen)", + "sunset_offset":"'sunset_offset': utligningen i tidspunktet for solnedgang - hvor lenge før (-) eller etter (+) tidspunktet solen går ned (lokalt) skal defineres som solnedgang (i sekunder - f. eks: '+3600' vil definere tidspunktet for solnedgang en time senere enn det faktiske tidspunktet for solnedgang)", + "sunset_time":"'sunset_time': definer tidspunktet for solnedgang manuelt (i følgende format: TT:MM:SS - f. eks: '20:30:00' vil definere tidspunktet for solnegang som halv-ni på kvelden)", + "take_over_control":"'take_over_control': dersom en annen tjeneste enn adaptiv belysning skrur lysene av eller på, vil automatisk adaptering av lyset stoppes inntil lyset (eller den tilhørende bryteren for adaptiv belysning) blir slått av - og på igjen", + "detect_non_ha_changes":"'detect_non_ha_changes': registrerer alle endringer i lysstyrke over 10% med opprinnelse utenfor Home Assistant - krever at 'take_over_control' er aktivert (OBS: tilkaller 'homeassistant.update_entity' ved hvert 'interval'!)", + "transition":"'transition': varigheten (i sekunder) på overgangen når lysene oppdateres (f.eks: dersom '45' er oppgitt, vil det være en 45 sekunders overgangsfase fra gjeldende lysinnstillinger og over til oppdaterte lysinnstillinger)" + } + } + }, + "error":{ + "option_error":"En eller flere valgte innstillinger er ugyldige" + } + } +} From 741225ab90efeca4b648acd5fcfeecc5e2697e02 Mon Sep 17 00:00:00 2001 From: covid10 <71146231+covid10@users.noreply.github.com> Date: Fri, 10 Dec 2021 17:27:42 +0100 Subject: [PATCH 28/31] Norwegian translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Norwegian (norsk bokmål) translation --- .../adaptive_lighting/translations/nb.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/custom_components/adaptive_lighting/translations/nb.json b/custom_components/adaptive_lighting/translations/nb.json index fbbfafee..2abeae9b 100644 --- a/custom_components/adaptive_lighting/translations/nb.json +++ b/custom_components/adaptive_lighting/translations/nb.json @@ -21,24 +21,24 @@ "description":"Alle innstillinger for en adaptiv belysning konfigurasjon. Innstillingene er identiske med innstillingene for YAML konfigurasjon. Ingen innstillinger vises dersom du har definert adaptive_lighting i din YAML konfigurasjon.", "data":{ "lights":"Lys / Lyskilder", - "initial_transition":"'initial_transition': varigheten på startovergangen (i sekunder) når lysene skrus av eller på - eller når 'sleep_state' endres", + "initial_transition":"'initial_transition': overgangen (i sekunder) når lysene skrus av eller på - eller når 'sleep_state' endres", "interval":"'interval': tiden mellom oppdateringer (i sekunder)", - "max_brightness":"'max_brightness': den høyeste lysstyrken (i prosent) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", - "max_color_temp":"'max_color_temp': den høyeste fargetemperaturen (i kelvin) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", - "min_brightness":"'min_brightness': den laveste lysstyrken (i prosent) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", - "min_color_temp":"'min_color_temp': den laveste fargetemperaturen (i kelvin) på lysene i løpet av en syklus (fra soloppgang til solnedgang)", + "max_brightness":"'max_brightness': den høyeste lysstyrken (i prosent) på lysene i løpet av en syklus", + "max_color_temp":"'max_color_temp': den høyeste fargetemperaturen (i kelvin) på lysene i løpet av en syklus", + "min_brightness":"'min_brightness': den laveste lysstyrken (i prosent) på lysene i løpet av en syklus", + "min_color_temp":"'min_color_temp': den laveste fargetemperaturen (i kelvin) på lysene i løpet av en syklus", "only_once":"'only_once': anvend innstillingene for adaptiv belysning kun når lysene skrus av eller på", "prefer_rgb_color":"'prefer_rgb_color': benytt rgb i stedet for fargetemperatur dersom det er mulig", "separate_turn_on_commands":"'separate_turn_on_commands': separer kommandone i 'light.turn_on' for hver attributt (farge, lysstyrke, osv.). Dette kan være nødvendig for enkelte typer lys / lyskilder", "sleep_brightness":"'sleep_brightness': lysstyrken på lysene (i prosent) når 'sleep_mode' (søvnmodus) er aktiv", "sleep_color_temp":"'sleep_color_temp': fargetemperaturen på lysene (i kelvin) når 'sleep_mode' (søvnmodus) er aktiv", - "sunrise_offset":"'sunrise_offset': utligningen i tidspunktet for soloppgang - hvor lenge før (-) eller etter (+) tidspunktet solen står opp (lokalt) skal defineres som soloppgang (i sekunder - f. eks: '-1800' vil definere tidspunktet for soloppgang en halvtime tidligere enn det faktiske tidspunktet for soloppgang)", - "sunrise_time":"'sunrise_time': definer tidspunktet for soloppgang manuelt (i følgende format: TT:MM:SS - f. eks: '08:00:00' vil definere tidspunktet for soloppgang som klokken 8 på morgenen)", - "sunset_offset":"'sunset_offset': utligningen i tidspunktet for solnedgang - hvor lenge før (-) eller etter (+) tidspunktet solen går ned (lokalt) skal defineres som solnedgang (i sekunder - f. eks: '+3600' vil definere tidspunktet for solnedgang en time senere enn det faktiske tidspunktet for solnedgang)", + "sunrise_offset":"'sunrise_offset': hvor lenge før (-) eller etter (+) tidspunktet solen står opp (lokalt) skal defineres som soloppgang (i sekunder)", + "sunrise_time":"'sunrise_time': definer tidspunktet for soloppgang manuelt (i følgende format: TT:MM:SS)", + "sunset_offset":"'sunset_offset': hvor lenge før (-) eller etter (+) tidspunktet solen går ned (lokalt) skal defineres som solnedgang (i sekunder)", "sunset_time":"'sunset_time': definer tidspunktet for solnedgang manuelt (i følgende format: TT:MM:SS - f. eks: '20:30:00' vil definere tidspunktet for solnegang som halv-ni på kvelden)", "take_over_control":"'take_over_control': dersom en annen tjeneste enn adaptiv belysning skrur lysene av eller på, vil automatisk adaptering av lyset stoppes inntil lyset (eller den tilhørende bryteren for adaptiv belysning) blir slått av - og på igjen", "detect_non_ha_changes":"'detect_non_ha_changes': registrerer alle endringer i lysstyrke over 10% med opprinnelse utenfor Home Assistant - krever at 'take_over_control' er aktivert (OBS: tilkaller 'homeassistant.update_entity' ved hvert 'interval'!)", - "transition":"'transition': varigheten (i sekunder) på overgangen når lysene oppdateres (f.eks: dersom '45' er oppgitt, vil det være en 45 sekunders overgangsfase fra gjeldende lysinnstillinger og over til oppdaterte lysinnstillinger)" + "transition":"'transition': varigheten (i sekunder) på overgangen når lysene oppdateres " } } }, From 21f088e82576a25ce4fd2795312e0d0bf14155df Mon Sep 17 00:00:00 2001 From: covid10 <71146231+covid10@users.noreply.github.com> Date: Sat, 11 Dec 2021 13:23:31 +0100 Subject: [PATCH 29/31] device_state_attributes warnings 2021.12.0b (#230) * device_state_attributes warnings 2021.12.0b Fix for device_state_attributes warnings which began in release 2021.12.0b * device_state_attributes warnings 2021.12.0b Fix for device_state_attributes warnings which began in release 2021.12.0b --- custom_components/adaptive_lighting/switch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index c07f8b5c..af826196 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -703,7 +703,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): return self._icon @property - def device_state_attributes(self) -> Dict[str, Any]: + def extra_state_attributes(self) -> Dict[str, Any]: """Return the attributes of the switch.""" if not self.is_on: return {key: None for key in self._settings} From b4138c7827df9106fe54ac750764f229743c3fe7 Mon Sep 17 00:00:00 2001 From: bedaes Date: Sat, 11 Dec 2021 22:01:26 +0100 Subject: [PATCH 30/31] Fix tuple expression in type annotation --- custom_components/adaptive_lighting/switch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index af826196..7e023134 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1074,7 +1074,7 @@ class SunLightSettings: def calculate_noon_and_midnight( sunset: datetime.datetime, sunrise: datetime.datetime - ) -> (datetime.datetime, datetime.datetime): + ) -> Tuple[datetime.datetime, datetime.datetime]: middle = abs(sunset - sunrise) / 2 if sunset > sunrise: noon = sunrise + middle From 87ba587d0fb7897b3fc908474102be15b81425b9 Mon Sep 17 00:00:00 2001 From: gvssr <61377476+gvssr@users.noreply.github.com> Date: Thu, 16 Dec 2021 09:22:33 +0100 Subject: [PATCH 31/31] Prettify integration name in HACS Add capitalized naming and removed underscore ( _ ) --- hacs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hacs.json b/hacs.json index 1de0dd51..500d0ebd 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,5 @@ { - "name": "adaptive_lighting", + "name": "Adaptive Lighting", "render_readme": true, "domains": ["switch"] }