Skip to content

Commit

Permalink
Merge branch 'main' into static
Browse files Browse the repository at this point in the history
  • Loading branch information
dala318 authored Dec 20, 2024
2 parents 1ea683f + 7bd50bf commit 16aa77f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nordpool_planner custom component for Home Assistant

Requires https://github.com/custom-components/nordpool
Requires https://github.com/custom-components/nordpool (not tested with new [HA native Nordpool](https://www.home-assistant.io/integrations/nordpool/), likely the sensor attributes are not same as the custom integration) or https://github.com/JaccoR/hass-entso-e

> **NOTE**: This is a based on https://github.com/jpulakka/nordpool_diff
Expand Down Expand Up @@ -139,8 +139,8 @@ I found it useful to setup a simple history graph chart comparing the values fro

Where from top to bottom my named entities are:

* nordpool_diff: duration 3 in search_length 10, accept_cost 2.0
* nordpool_diff: duration 2 in search_length 5, accept_cost 2.0 and accept_rate 0.7
* nordpool_planner: duration 3 in search_length 10, accept_cost 2.0
* nordpool_planner: duration 2 in search_length 5, accept_cost 2.0 and accept_rate 0.7
* nordpool average: just a template sensor extracting the nordpool attribute average to an entity for easier tracking and comparisons "{{ state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'average') | float }}"
* nordpool
* nordpool_diff:
27 changes: 27 additions & 0 deletions custom_components/nordpool_planner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
self.low_cost_state = NordpoolPlannerState()
self.high_cost_state = NordpoolPlannerState()

def as_dict(self):
"""For diagnostics serialization."""
res = self.__dict__.copy()
for k, i in res.copy().items():
if "_number_entity" in k:
res[k] = {"id": i, "value": self.get_number_entity_value(i)}
return res

async def async_setup(self):
"""Post initialization setup."""
# Ensure an update is done on every hour
Expand Down Expand Up @@ -626,6 +634,10 @@ def __init__(self, unique_id: str) -> None:
self._unique_id = unique_id
self._np = None

def as_dict(self):
"""For diagnostics serialization."""
return self.__dict__

@property
def unique_id(self) -> str:
"""Get the unique id."""
Expand Down Expand Up @@ -797,6 +809,10 @@ def on_at(self, time: dt.datetime) -> bool:
return self.starts_at < time
return False

def as_dict(self):
"""For diagnostics serialization."""
return self.__dict__


class NordpoolPlannerStatus:
"""Status for the overall planner."""
Expand All @@ -820,6 +836,17 @@ def __init__(
self._planner = planner
self._attr_device_info = planner.get_device_info()

def as_dict(self):
"""For diagnostics serialization."""
return {
k: v
for k, v in self.__dict__.items()
if not (
k.startswith("_")
or k in ["hass", "platform", "registry_entry", "device_entry"]
)
}

@property
def should_poll(self):
"""No need to poll. Coordinator notifies entity of updates."""
Expand Down
30 changes: 30 additions & 0 deletions custom_components/nordpool_planner/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Diagnostics support for Nordpool Planner."""

from __future__ import annotations

# import json
import logging
from typing import Any

# from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from . import NordpoolPlanner
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)

# TO_REDACT = []


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, config_entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
diag_data = {
# "config_entry": config_entry, # Already included in the planner
"planner": hass.data[DOMAIN][config_entry.entry_id],
}

return diag_data

0 comments on commit 16aa77f

Please sign in to comment.