Skip to content

Commit 977a57b

Browse files
committed
initial version
0 parents  commit 977a57b

25 files changed

+1327
-0
lines changed

.devcontainer.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "fireson/zendure_h2k",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.13",
4+
"postCreateCommand": "scripts/setup",
5+
"forwardPorts": [
6+
8123
7+
],
8+
"portsAttributes": {
9+
"8123": {
10+
"label": "Home Assistant",
11+
"onAutoForward": "notify"
12+
}
13+
},
14+
"customizations": {
15+
"vscode": {
16+
"extensions": [
17+
"charliermarsh.ruff",
18+
"github.vscode-pull-request-github",
19+
"ms-python.python",
20+
"ms-python.vscode-pylance",
21+
"ryanluker.vscode-coverage-gutters"
22+
],
23+
"settings": {
24+
"files.eol": "\n",
25+
"editor.tabSize": 4,
26+
"editor.formatOnPaste": true,
27+
"editor.formatOnSave": true,
28+
"editor.formatOnType": false,
29+
"files.trimTrailingWhitespace": true,
30+
"python.analysis.typeCheckingMode": "basic",
31+
"python.analysis.autoImportCompletions": true,
32+
"python.defaultInterpreterPath": "/usr/local/bin/python",
33+
"[python]": {
34+
"editor.defaultFormatter": "charliermarsh.ruff"
35+
}
36+
}
37+
}
38+
},
39+
"remoteUser": "vscode",
40+
"features": {
41+
"ghcr.io/devcontainers-extra/features/apt-packages:1": {
42+
"packages": [
43+
"ffmpeg",
44+
"libturbojpeg0",
45+
"libpcap-dev"
46+
]
47+
}
48+
}
49+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# artifacts
2+
__pycache__
3+
.pytest*
4+
*.egg-info
5+
*/build/*
6+
*/dist/*
7+
8+
9+
# misc
10+
.coverage
11+
.vscode
12+
coverage.xml
13+
.ruff_cache
14+
15+
16+
# Home Assistant configuration
17+
config/*
18+
!config/configuration.yaml
19+
/.vs/Fireson
20+
/.vs

.ruff.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml
2+
3+
target-version = "py312"
4+
5+
[lint]
6+
select = [
7+
"ALL",
8+
]
9+
10+
ignore = [
11+
"ANN101", # Missing type annotation for `self` in method
12+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
13+
"D203", # no-blank-line-before-class (incompatible with formatter)
14+
"D212", # multi-line-summary-first-line (incompatible with formatter)
15+
"COM812", # incompatible with formatter
16+
"ISC001", # incompatible with formatter
17+
]
18+
19+
[lint.flake8-pytest-style]
20+
fixture-parentheses = false
21+
22+
[lint.pyupgrade]
23+
keep-runtime-typing = true
24+
25+
[lint.mccabe]
26+
max-complexity = 25

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 peteS-UK
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Zendure Integration
2+
3+
This integration Integrates the Hyper2000 into Home Assistant.
4+
It seems possible to set the actual charge and discarge values, but this is not implemented yet.But testing seems hopefull :-)
5+
6+
## Features
7+
8+
- Get all telemetry data from your Hyper 2000
9+
10+
### 1.0.6 (2025-02-27) ALPHA
11+
12+
- First try to adjust battery output based upon home assistant sensor (for example P1 meter).
13+
14+
### 1.0.5 (2025-02-24) ALPHA
15+
16+
- The values are read from the Hyper 2000 and displayed in Home Assistant. Each 90 seconds the values are updated, or sooner when they are changing.
17+
- You need to specify your Zendure username + password during the configuration of the integration. All your hyper2000 devices are found in the cloud. If you want to see the details enable the debug logging for the integration.
18+
- Not all the sensors have the correct unit of measurement. This will be fixed in a later version.
19+
20+
## License
21+
22+
MIT License

config/configuration.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://www.home-assistant.io/integrations/default_config/
2+
default_config:
3+
4+
# https://www.home-assistant.io/integrations/homeassistant/
5+
homeassistant:
6+
debug: true
7+
8+
# https://www.home-assistant.io/integrations/logger/
9+
logger:
10+
default: info
11+
logs:
12+
custom_components.zendure_h2k: debug
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# zendure_h2k/README.md
2+
3+
# Zendure H2K Integration
4+
5+
This project is a custom integration for Home Assistant that allows users to connect and manage their Zendure devices, specifically the Hyper 2000 model.
6+
7+
## Overview
8+
9+
The Zendure H2K integration provides a seamless way to interact with Zendure's API, enabling users to retrieve device information, manage connections, and utilize MQTT for real-time updates.
10+
11+
## Files
12+
13+
- `custom_components/zendure_h2k/__init__.py`: Marks the directory as a Python package and may contain initialization code.
14+
- `custom_components/zendure_h2k/api.py`: Contains the `API` class for handling connections to the Zendure API, managing authentication, and retrieving device information.
15+
- `custom_components/zendure_h2k/hyper2000.py`: Defines the `Hyper2000` class, representing the Hyper 2000 device with relevant properties and methods.
16+
- `custom_components/zendure_h2k/manifest.json`: Contains metadata about the custom component, including its name, version, and dependencies.
17+
- `.gitignore`: Specifies files and directories to be ignored by Git.
18+
19+
## Installation
20+
21+
1. Clone this repository to your local machine.
22+
2. Copy the `zendure_h2k` folder into your Home Assistant `custom_components` directory.
23+
3. Restart Home Assistant to load the new integration.
24+
25+
## Usage
26+
27+
After installation, configure the integration in Home Assistant by providing your Zendure account credentials. The integration will automatically discover and manage your Hyper 2000 devices.
28+
29+
## Contributing
30+
31+
Contributions are welcome! Please submit a pull request or open an issue for any enhancements or bug fixes.
32+
33+
## License
34+
35+
This project is licensed under the MIT License. See the LICENSE file for more details.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""The Zendure Integration integration."""
2+
3+
from __future__ import annotations
4+
from collections.abc import Callable
5+
from dataclasses import dataclass
6+
import logging
7+
8+
from homeassistant.config_entries import ConfigEntry
9+
from homeassistant.const import Platform
10+
from homeassistant.core import HomeAssistant
11+
from homeassistant.exceptions import ConfigEntryNotReady
12+
from homeassistant.helpers.device_registry import DeviceEntry
13+
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
14+
15+
from .hypermanager import HyperManager
16+
17+
_LOGGER = logging.getLogger(__name__)
18+
19+
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SELECT, Platform.SENSOR]
20+
21+
type MyConfigEntry = ConfigEntry[RuntimeData]
22+
23+
24+
@dataclass
25+
class RuntimeData:
26+
"""Class to hold your data."""
27+
28+
coordinator: DataUpdateCoordinator
29+
30+
31+
async def async_setup_entry(hass: HomeAssistant, config_entry: MyConfigEntry) -> bool:
32+
"""Set up Zendure Integration from a config entry."""
33+
34+
coordinator = HyperManager(hass, config_entry)
35+
config_entry.runtime_data = RuntimeData(coordinator)
36+
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
37+
38+
_LOGGER.debug("Open API connection")
39+
if not await coordinator.initialize():
40+
raise ConfigEntryNotReady
41+
42+
await coordinator.async_config_entry_first_refresh()
43+
44+
config_entry.async_on_unload(config_entry.add_update_listener(_async_update_listener))
45+
46+
# Return true to denote a successful setup.
47+
return True
48+
49+
50+
async def _async_update_listener(hass: HomeAssistant, config_entry):
51+
"""Handle config options update."""
52+
# Reload the integration when the options change.
53+
await hass.config_entries.async_reload(config_entry.entry_id)
54+
55+
56+
async def async_remove_config_entry_device(hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry) -> bool:
57+
"""Delete device if selected from UI."""
58+
# Adding this function shows the delete device option in the UI.
59+
# Remove this function if you do not want that option.
60+
# You may need to do some checks here before allowing devices to be removed.
61+
return True
62+
63+
64+
async def async_unload_entry(hass: HomeAssistant, config_entry: MyConfigEntry) -> bool:
65+
"""Unload a config entry."""
66+
# This is called when you remove your integration or shutdown HA.
67+
# If you have created any custom services, they need to be removed here too.
68+
69+
# Unload platforms and return result
70+
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)

0 commit comments

Comments
 (0)