Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Add IP sensor; visit device; DE translation
Browse files Browse the repository at this point in the history
  • Loading branch information
a529987659852 committed Dec 5, 2021
1 parent 2a42622 commit b5e529c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
5 changes: 4 additions & 1 deletion custom_components/openwbmqtt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The openwbmqtt component for controlling the openWB wallbox via home assistant / MQTT"""
import logging
from homeassistant.const import CONF_HOST

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand All @@ -15,12 +16,14 @@

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Setup openWB sensors (--> display current data in home assistant) and services (--> change openWB settings)."""

"""
# Provide data obtained in the configuration flow so that it can be used when setting up the entries.
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
MQTT_ROOT_TOPIC: entry.data[MQTT_ROOT_TOPIC],
CHARGE_POINTS: entry.data[CHARGE_POINTS],
CONF_HOST: entry.data[CONF_HOST],
}
"""

# Trigger the creation of sensors.
for platform in PLATFORMS:
Expand Down
30 changes: 29 additions & 1 deletion custom_components/openwbmqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
LENGTH_KILOMETERS,
PERCENTAGE,
POWER_WATT,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
CONF_HOST
)
from homeassistant.helpers.entity import EntityDescription

# Global values
DOMAIN = "openwbmqtt"
Expand All @@ -40,6 +44,7 @@
{
vol.Required(MQTT_ROOT_TOPIC, default=MQTT_ROOT_TOPIC_DEFAULT): cv.string,
vol.Required(CHARGE_POINTS, default=DEFAULT_CHARGE_POINTS): cv.positive_int,
vol.Optional(CONF_HOST, default=""): str,
}
)

Expand Down Expand Up @@ -68,8 +73,17 @@ class openwbSensorEntityDescription(SensorEntityDescription):
3: "Stop",
4: "Standby",
},
entity_category=ENTITY_CATEGORY_CONFIG,
),
]
openwbSensorEntityDescription(
key="system/IpAddress",
name="IP-Adresse",
device_class=None,
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
icon='mdi:earth'
),]

"""
List of sensors which are relevant for each charge point.
Expand Down Expand Up @@ -97,13 +111,15 @@ class openwbSensorEntityDescription(SensorEntityDescription):
device_class=DEVICE_CLASS_ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="AConfigured",
name="Ladestrom (Soll)",
device_class=DEVICE_CLASS_CURRENT,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="kmCharged",
Expand All @@ -120,6 +136,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="ChargePointEnabled",
Expand All @@ -128,6 +145,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="%Soc",
Expand Down Expand Up @@ -156,6 +174,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
device_class=None,
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="boolPlugStat",
Expand All @@ -165,6 +184,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
icon="mdi:connection",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="boolChargeStat",
Expand All @@ -174,6 +194,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
icon="mdi:connection",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="boolChargeAtNight",
Expand All @@ -183,6 +204,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
icon="mdi:weather-night",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="TimeRemaining",
Expand All @@ -199,6 +221,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:form-textbox",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="kWhDailyCharged",
Expand All @@ -214,6 +237,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="boolDirectChargeModeSoc",
Expand All @@ -222,6 +246,7 @@ class openwbSensorEntityDescription(SensorEntityDescription):
native_unit_of_measurement=None,
state_class=STATE_CLASS_MEASUREMENT,
valueMap={1: True, 0: False},
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="kWhCounter",
Expand All @@ -236,20 +261,23 @@ class openwbSensorEntityDescription(SensorEntityDescription):
device_class=DEVICE_CLASS_BATTERY,
native_unit_of_measurement=None,
state_class=PERCENTAGE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="PfPhase2",
name="cos(Phi) (Phase 2)",
device_class=DEVICE_CLASS_BATTERY,
native_unit_of_measurement=None,
state_class=PERCENTAGE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="PfPhase3",
name="cos(Phi) (Phase 3)",
device_class=DEVICE_CLASS_BATTERY,
native_unit_of_measurement=None,
state_class=PERCENTAGE,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
openwbSensorEntityDescription(
key="VPhase1",
Expand Down
28 changes: 19 additions & 9 deletions custom_components/openwbmqtt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
CONF_HOST,
)
from homeassistant.components import mqtt
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
Expand All @@ -18,6 +19,8 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import dt, slugify

from homeassistant.helpers.entity import DeviceInfo

# Import global values.
from .const import (
CHARGE_POINTS,
Expand All @@ -40,9 +43,13 @@ async def async_setup_entry(

"""Reuse data obtained in the configuration flow so that it can be used when setting up the entries.
Data flow is config_flow.py --> data --> init.py --> hass.data --> sensor.py --> hass.data"""
nChargePoints = hass.data[DOMAIN][config.entry_id][CHARGE_POINTS]
mqttRoot = hass.data[DOMAIN][config.entry_id][MQTT_ROOT_TOPIC]
# nChargePoints = hass.data[DOMAIN][config.entry_id][CHARGE_POINTS]
# mqttRoot = hass.data[DOMAIN][config.entry_id][MQTT_ROOT_TOPIC]
# confHost = hass.data[DOMAIN][config.entry_id][CONF_HOST]
integrationUniqueID = config.unique_id
mqttRoot = config.data[MQTT_ROOT_TOPIC]
nChargePoints = config.data[CHARGE_POINTS]
confHost = config.data[CONF_HOST]

sensorList = []
# Create all global sensors.
Expand All @@ -51,7 +58,7 @@ async def async_setup_entry(
description.mqttTopic = f"{mqttRoot}/{description.key}"
_LOGGER.debug("mqttTopic: %s", description.mqttTopic)
sensorList.append(
openwbSensor(uniqueID=integrationUniqueID, description=description)
openwbSensor(uniqueID=integrationUniqueID, description=description, confHost=confHost)
)

# Create all sensors for each charge point, respectively.
Expand All @@ -68,6 +75,7 @@ async def async_setup_entry(
description=description,
nChargePoints=int(nChargePoints),
currentChargePoint=chargePoint,
confHost=confHost,
)
)

Expand All @@ -82,18 +90,20 @@ class openwbSensor(SensorEntity):
def __init__(
self,
uniqueID: str | None,
confHost: str | None,
description: openwbSensorEntityDescription,
nChargePoints: int | None = None,
currentChargePoint: int | None = None,
) -> None:
"""Initialize the sensor."""
# Group all sensors to one device. The device is identified by the prefix (which is unique).
self._attr_device_info = {
ATTR_NAME: uniqueID,
ATTR_IDENTIFIERS: {(DOMAIN, uniqueID)},
ATTR_MANUFACTURER : MANUFACTURER,
ATTR_MODEL: MODEL,
}
self._attr_device_info = DeviceInfo(
name= uniqueID,
identifiers= {(DOMAIN, uniqueID)},
manufacturer= MANUFACTURER,
model= MODEL,
configuration_url=f"http://{confHost}/openWB/web/index.php",
)
self.entity_description = description
if nChargePoints:
self._attr_unique_id = slugify(
Expand Down
18 changes: 18 additions & 0 deletions custom_components/openwbmqtt/translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"config": {
"abort": {
"already_configured": "Die Integration dieser openWB ist bereits konfiguriert. Bitte gib ein anderes MQTT-Wurzeltopic ein."
},
"step": {
"user": {
"data": {
"mqttroot": "MQTT-Wurzeltopic",
"chargepoints": "Anzahl der Ladepunkte der openWB",
"host": "IP-Adresse der openWB (nur Navigation zum openWB-UI)"
},
"description": "Richte die openWB-Integration ein.",
"title": "openWB-Integration in Home Assistant mittels MQTT"
}
}
}
}

0 comments on commit b5e529c

Please sign in to comment.