-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,926 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
custom_components/custom_components/weishaupt_modbus/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .const import CONST | ||
|
||
PLATFORMS: list[str] = [ | ||
"number", | ||
"select", | ||
"sensor", | ||
# "switch", | ||
] | ||
|
||
|
||
# Return boolean to indicate that initialization was successful. | ||
# return True | ||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
# 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"]) | ||
|
||
# This creates each HA object for each platform your device requires. | ||
# It's done by calling the `async_setup_entry` function in each platform module. | ||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
# 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[CONST.DOMAIN].pop(entry.entry_id) | ||
|
||
return unload_ok |
80 changes: 80 additions & 0 deletions
80
custom_components/custom_components/weishaupt_modbus/config_flow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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 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 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 | ||
# The exceptions are defined at the end of this file, and are used in the | ||
# `async_step_user` method below. | ||
if len(data["host"]) < 3: | ||
raise InvalidHost | ||
|
||
# If your PyPI package is not built with async, pass your methods | ||
# to the executor: | ||
# await hass.async_add_executor_job( | ||
# your_validate_func, data["username"], data["password"] | ||
# ) | ||
|
||
# If you cannot connect: | ||
# throw CannotConnect | ||
# If the authentication is wrong: | ||
# InvalidAuth | ||
|
||
# Return info that you want to store in the config entry. | ||
# "Title" is what is displayed to the user for this hub device | ||
# It is stored internally in HA as part of the device config. | ||
# See `async_step_user` below for how this is used | ||
return {"title": data["host"]} | ||
|
||
|
||
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 | ||
# automatically. This example uses PUSH, as the dummy hub will notify HA of | ||
# changes. | ||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH | ||
|
||
async def async_step_user(self, user_input=None): | ||
# 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`), | ||
# and when that has some validated input, it calls `async_create_entry` to | ||
# actually create the HA config entry. Note the "title" value is returned by | ||
# `validate_input` above. | ||
errors = {} | ||
if user_input is not None: | ||
try: | ||
info = await validate_input(self.hass, user_input) | ||
|
||
return self.async_create_entry(title=info["title"], data=user_input) | ||
|
||
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. | ||
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.""" |
51 changes: 51 additions & 0 deletions
51
custom_components/custom_components/weishaupt_modbus/const.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from dataclasses import dataclass | ||
from datetime import timedelta | ||
from homeassistant.const import ( | ||
UnitOfEnergy, | ||
UnitOfTemperature, | ||
UnitOfTime, | ||
UnitOfVolumeFlowRate, | ||
UnitOfPower, | ||
PERCENTAGE, | ||
) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class MainConstants: | ||
DOMAIN = "weishaupt_wbb" | ||
SCAN_INTERVAL = timedelta(minutes=1) | ||
UNIQUE_ID = "unique_id" | ||
APPID = 100 | ||
KENNFELDFILE = "weishaupt_wbb_kennfeld.json" | ||
|
||
|
||
CONST = MainConstants() | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FormatConstants: | ||
TEMPERATUR = UnitOfTemperature.CELSIUS | ||
ENERGY = UnitOfEnergy.KILO_WATT_HOUR | ||
POWER = UnitOfPower.WATT | ||
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" | ||
SENSOR_CALC = "Sensor_Calc" | ||
SELECT = "Select" | ||
NUMBER = "Number" | ||
NUMBER_RO = "Number_RO" | ||
|
||
|
||
TYPES = TypeConstants() |
Oops, something went wrong.