Skip to content

Commit

Permalink
Configuration overhaul
Browse files Browse the repository at this point in the history
- Moved "options" to basic configuration
  - `scan_interval` and `debug_mode`can now be set under the (...) menu
    using the "Reconfigure" option
- Made configuration editable by providing `async_setup_reconfigure` function
  (see above)
- Added serial number to device in integration overview
- Disabled `OptionsFlowHandler` class since there are no more options ;)
- Disabled some functions that were never called
- Reworked config reload to be compatible with HA 2025.1 onward
- Added/removed translations where appropriate
- Removed unused constants
- Fixed a bug that caused the sensors to be read every second thereby
  causing unnecessary load

Signed-off-by: stefan <[email protected]>
  • Loading branch information
RustyDust committed Dec 26, 2024
1 parent a10dcf0 commit 00db8e7
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 215 deletions.
30 changes: 9 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ha_sonnenbatterie
Homeassistant integration to show many stats of Sonnenbatterie

Should work with current versions of Sonnenbatterie.
that should work with current versions of Sonnenbatterie.

[![Validate with hassfest](https://github.com/weltmeyer/ha_sonnenbatterie/actions/workflows/hassfest.yaml/badge.svg)](https://github.com/weltmeyer/ha_sonnenbatterie/actions/workflows/hassfest.yaml)

Expand All @@ -14,37 +13,26 @@ Should work with current versions of Sonnenbatterie.
* ex. model 9.2 eco from 2014 not working

## Important: ###
Set the update interval in the Integration Settings. Default is 10 seconds, which may kill your recorder database
Set the update interval in the Integration Settings. Default is 30 seconds, don't
go below 10 seconds otherwise you might encounter an exploding recorder database.

### Unused/Unavailable sensors
### Problems and/or Unused/Unavailable sensors
Depending on the software on and the oparting mode of your Sonnenbatterie some
values may not be available. The integration does it's best to detect the absence
of these values. If a value isn't returned by your Sonnenbatterie you will see
entries like the following in your log:

```
… WARNING (Thread-1 (watcher)) [custom_components.sonnenbatterie] No 'ppv2' in inverter -> sensor disabled
… WARNING (Thread-1 (watcher)) [custom_components.sonnenbatterie] No 'ipv' in inverter -> sensor disabled
… WARNING (Thread-1 (watcher)) [custom_components.sonnenbatterie] No 'ipv2' in inverter -> sensor disabled
… WARNING (Thread-1 (watcher)) [custom_components.sonnenbatterie] No 'upv' in inverter -> sensor disabled
… WARNING (Thread-1 (watcher)) [custom_components.sonnenbatterie] No 'upv2' in inverter -> sensor disabled
```

Those aren't errors! There's nothing to worry about. This just tells you that
your Sonnenbatterie doesn't provide these values.

If you feel that your Sonnenbatterie **should** provide one or more of those
you can enable the "debug_mode" from

_Settings -> Devices & Services -> Integrations -> Sonnenbatterie_
_Settings -> Devices & Services -> Integrations -> Sonnenbatterie -> (...) -> Reconfigure_

Just enable the "Debug mode" and restart your HomeAssistant instance. You'll get
the full data that's returned by your Sonnenbatterie in the logs. Please put those
logs along with the setting you want monitored into a new issue.
Just enable the "Debug mode" and watch the logs of your HomeAssistant instance.
You'll get the full data that's returned by your Sonnenbatterie in the logs.
Please put those logs along with the setting you want monitored into a new issue.

## Install
Easiest way is to add this repository to hacs.

Easiest way is to add this repository is to use [HACS](https://hacs.xyz).

## Screenshots :)
![image](https://user-images.githubusercontent.com/1668465/78452159-ed2d7d80-7689-11ea-9e30-3a66ecc2372a.png)
42 changes: 19 additions & 23 deletions custom_components/sonnenbatterie/__init__.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
"""The Sonnenbatterie integration."""

from .const import *
import json

# from homeassistant.helpers.entity import Entity
from homeassistant.const import (
CONF_SCAN_INTERVAL,
Platform
)

from .const import *

async def async_setup(hass, config):
hass.data.setdefault(DOMAIN, {})
"""Set up a skeleton component."""
# if DOMAIN not in config:
# hass.states.async_set('sonnenbatterie.test', 'Works!')
# return True

# hass.states.async_set('sonnenbatterie.test', 'Works!')
return True
# rustydust_241227: this doesn't seem to be needed - kept until we're sure ;)
# async def async_setup(hass, config):
# """Set up a skeleton component."""
# hass.data.setdefault(DOMAIN, {})
# return True


async def async_setup_entry(hass, config_entry):
LOGGER.info("setup_entry: " + json.dumps(dict(config_entry.data)))

LOGGER.debug("setup_entry: " + json.dumps(dict(config_entry.data)))
await hass.config_entries.async_forward_entry_setups(config_entry, [ Platform.SENSOR ])
config_entry.add_update_listener(update_listener)
# rustydust_241227: this doesn't seem to be needed
# config_entry.add_update_listener(update_listener)
config_entry.async_on_unload(config_entry.add_update_listener(async_reload_entry))
return True


async def async_reload_entry(hass, entry):
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)


async def update_listener(hass, entry):
LOGGER.info("Update listener" + json.dumps(dict(entry.options)))
hass.data[DOMAIN][entry.entry_id]["monitor"].update_interval_seconds = (
entry.options.get(CONF_SCAN_INTERVAL)
)
# rustydust_241227: this doesn't seem to be needed
# async def update_listener(hass, entry):
# LOGGER.warning("Update listener" + json.dumps(dict(entry.options)))
# # hass.data[DOMAIN][entry.entry_id]["monitor"].update_interval_seconds = (
# # entry.options.get(CONF_SCAN_INTERVAL)
# # )


async def async_unload_entry(hass, entry):
"""Handle removal of an entry."""
return await hass.config_entries.async_forward_entry_unload(entry, "sensor")
return await hass.config_entries.async_forward_entry_unload(entry, Platform.SENSOR)
Loading

0 comments on commit 00db8e7

Please sign in to comment.