Skip to content

Commit

Permalink
Merge branch 'OStrama-main' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
MadOne committed Oct 9, 2024
2 parents 2f5c516 + df9795a commit 94391a8
Show file tree
Hide file tree
Showing 17 changed files with 1,467 additions and 1,664 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 MadOne
Copyright (c) 2024 OStrama

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# THIS INTEGRATION IS NOT LONGER DEVELOPED.
# There is a far superior approach at:
# https://github.com/OStrama/weishaupt_modbus


This is a fork from MadOne: https://github.com/MadOne/weishaupt_modbus/

I started to build a structure that finally will allow loading of the modbus structure from a file.
As a first step, all modbus parameters will be concentrated in the file hpconst.py as a set of object lists.
This allows generic setup of all entities and a more easy completion of messages and entity behavior

#### not yet ready ####

For production, please use https://github.com/MadOne/weishaupt_modbus/ for now.
When it's ready, I'll distribute this fork via HACS

# Weishaupt_modbus

Expand All @@ -15,15 +17,15 @@ This is how it might look:

## Installation

### Install through HACS
### Install through HACS

- Not working yet

### HACS (manually add Repository)

Add this repository to HACS.
* In the HACS GUI, select "Custom repositories"
* Enter the following repository URL: https://github.com/MadOne/weishaupt_modbus/releases
* Enter the following repository URL: https://github.com/OStrama/weishaupt_modbus/releases
* Category: Integration
* After adding the integration, restart Home Assistant.
* Now under Configuration -> Integrations, "Weishaupt Modbus Integration" should be available.
Expand All @@ -43,15 +45,15 @@ custom_components
│ ├── ...
│ ├── ...
│ ├── ...
│ └── wp.py
│ └── wp.py
```
## Configuration

![Bildschirmfoto vom 2024-07-31 21-46-18](https://github.com/user-attachments/assets/45ad403e-c721-40bd-b723-95fe05fca5c5)

Just enter the IP of your Weishaupt heatpump. Port should be ok at default unless you changed it in the Heatpump configuration.

You have to enable modbus in your heatpump settings.
You have to enable modbus in your heatpump settings.


## Setting up the HeatPump
Expand Down
12 changes: 3 additions & 9 deletions custom_components/weishaupt_modbus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
"""Weishaupt Modbus Integration."""

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .const import CONST

PLATFORMS: list[str] = [
"number",
"select",
"sensor",
"switch",
# "switch",
]


# Return boolean to indicate that initialization was successful.
# return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Hello World from a config entry."""
# Store an instance of the "connecting" class that does the work of speaking
# with your actual devices.
# hass.data.setdefault(DOMAIN, {})[entry.entry_id] = hub.Hub(hass, entry.data["host"])
Expand All @@ -26,14 +22,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
# This is called when an entry/configured device is to be removed. The class
# needs to unload itself, and remove callbacks. See the classes for further
# details
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
hass.data[CONST.DOMAIN].pop(entry.entry_id)

return unload_ok
24 changes: 3 additions & 21 deletions custom_components/weishaupt_modbus/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
"""Weishaupt Modbus Integration."""

from typing import Any

import voluptuous as vol

from homeassistant import config_entries, exceptions
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

# from . import wp
from .const import DOMAIN
from .const import CONST

# DATA_SCHEMA = vol.Schema({("host"): str, ("port"): cv.port})
DATA_SCHEMA = vol.Schema(
{vol.Required(CONF_HOST): str, vol.Optional(CONF_PORT, default="502"): cv.port}
)


async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
# Validate the data can be used to set up a connection.

# This is a simple example to show an error in the UI for a short hostname
Expand All @@ -31,10 +22,6 @@ async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]:
if len(data["host"]) < 3:
raise InvalidHost

# whp = wp.heat_pump("10.10.1.225", 502)
# if not whp:
# raise ConnectionFailed

# If your PyPI package is not built with async, pass your methods
# to the executor:
# await hass.async_add_executor_job(
Expand All @@ -53,9 +40,7 @@ async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]:
return {"title": data["host"]}


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Hello World."""

class ConfigFlow(config_entries.ConfigFlow, domain=CONST.DOMAIN):
VERSION = 1
# Pick one of the available connection classes in homeassistant/config_entries.py
# This tells HA if it should be asking for updates, or it'll be notified of updates
Expand All @@ -64,7 +49,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH

async def async_step_user(self, user_input=None):
"""Handle the initial step."""
# This goes through the steps to take the user through the setup process.
# Using this it is possible to update the UI and prompt for additional
# information. This example provides a single form (built from `DATA_SCHEMA`),
Expand All @@ -81,15 +65,13 @@ async def async_step_user(self, user_input=None):
except Exception: # noqa: BLE001
errors["base"] = "unknown"

# If there is no user input or there were errors, show the form again, including any errors that were found with the input.
# If there is no user input or there were errors, show the form again, including any errors that were found with the input.
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)


class InvalidHost(exceptions.HomeAssistantError):
"""Error to indicate there is an invalid hostname."""


class ConnectionFailed(exceptions.HomeAssistantError):
"""Error to indicate there is an invalid hostname."""
40 changes: 34 additions & 6 deletions custom_components/weishaupt_modbus/const.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
"""Constants."""

from dataclasses import dataclass
from datetime import timedelta
from homeassistant.const import UnitOfEnergy, UnitOfTemperature, UnitOfTime, UnitOfVolumeFlowRate, PERCENTAGE

@dataclass(frozen=True)
class MainConstants:
DOMAIN = "weishaupt_wbb"
SCAN_INTERVAL = timedelta(minutes=1)
UNIQUE_ID = "unique_id"
APPID = 100

CONST = MainConstants()

@dataclass(frozen=True)
class FormatConstants:
TEMPERATUR = UnitOfTemperature.CELSIUS
ENERGY = UnitOfEnergy.KILO_WATT_HOUR
PERCENTAGE = PERCENTAGE
NUMBER = ""
STATUS = "Status"
VOLUMENSTROM = UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR
KENNLINIE = "Stg."
TIME_MIN = UnitOfTime.MINUTES
TIME_H = UnitOfTime.HOURS

FORMATS = FormatConstants()

@dataclass(frozen=True)
class TypeConstants:
SENSOR = "Sensor"
SELECT = "Select"
NUMBER = "Number"
NUMBER_RO = "Number_RO"

TYPES = TypeConstants()

DOMAIN = "weishaupt_modbus"
SCAN_INTERVAL = timedelta(minutes=1)
UNIQUE_ID = "unique_id"
APPID = 100
Loading

0 comments on commit 94391a8

Please sign in to comment.