Skip to content

Commit

Permalink
- Sensor Names translated (de)
Browse files Browse the repository at this point in the history
- v1.0.2
  • Loading branch information
marq24 committed Oct 4, 2023
1 parent 269ab6c commit b62b34c
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 34 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/hacs.yaml

This file was deleted.

24 changes: 20 additions & 4 deletions custom_components/tibber_local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import logging
import json

import voluptuous as vol

from datetime import timedelta
Expand All @@ -22,6 +24,7 @@
)

_LOGGER = logging.getLogger(__name__)
_LANG = None
SCAN_INTERVAL = timedelta(seconds=10)
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)

Expand All @@ -40,10 +43,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
DEFAULT_SCAN_INTERVAL)))

_LOGGER.info("Starting TibberLocal with interval: " + str(SCAN_INTERVAL))

load_translation(hass)
session = async_get_clientsession(hass)

coordinator = TibberLocalDataUpdateCoordinator(hass, session, config_entry)
coordinator = TibberLocalDataUpdateCoordinator(hass, session, config_entry, lang=_LANG)

await coordinator.async_refresh()

Expand All @@ -60,14 +63,27 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
return True


def load_translation(hass):
"""Load correct language file or default to english"""
global _LANG # pylint: disable=global-statement
basepath = __file__[:-11]
file = f"{basepath}translations/local.{hass.config.language.lower()}.json"
try:
with open(file) as f: # pylint: disable=unspecified-encoding,invalid-name
_LANG = json.load(f)
except: # pylint: disable=unspecified-encoding,bare-except,invalid-name
with open(f"{basepath}translations/local.en.json") as f:
_LANG = json.load(f)


class TibberLocalDataUpdateCoordinator(DataUpdateCoordinator):
def __init__(self, hass: HomeAssistant, session, config_entry):
def __init__(self, hass: HomeAssistant, session, config_entry, lang=None):
self._host = config_entry.options.get(CONF_HOST, config_entry.data[CONF_HOST])
the_pwd = config_entry.options.get(CONF_PASSWORD, config_entry.data[CONF_PASSWORD])
self.bridge = TibberLocalBridge(host=self._host, pwd=the_pwd, websession=session, options=None)
self.name = config_entry.title
self._config_entry = config_entry
self._statistics_available = False
self.lang = lang
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)

# Callable[[Event], Any]
Expand Down
8 changes: 4 additions & 4 deletions custom_components/tibber_local/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Zählerstand Total
SensorEntityDescription(
key="0100010800ff",
name="Home import",
name="Import total",
entity_registry_enabled_default = False,
native_unit_of_measurement=ENERGY_WATT_HOUR,
icon="mdi:home-import-outline",
Expand All @@ -39,7 +39,7 @@
# Wirkenergie Total
SensorEntityDescription(
key="0100020800ff",
name="Home export",
name="Export total",
entity_registry_enabled_default = False,
native_unit_of_measurement=ENERGY_WATT_HOUR,
icon="mdi:home-export-outline",
Expand All @@ -48,7 +48,7 @@
),
SensorEntityDescription(
key="0100010800ff_in_k",
name="Home import (kWh)",
name="Import total (kWh)",
suggested_display_precision = 5,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
icon="mdi:home-import-outline",
Expand All @@ -57,7 +57,7 @@
),
SensorEntityDescription(
key="0100020800ff_in_k",
name="Home export (kWh)",
name="Export total (kWh)",
suggested_display_precision = 5,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
icon="mdi:home-export-outline",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tibber_local/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-tibber-pulse-local/issues",
"requirements": ["smllib==1.2"],
"version": "1.0.1"
"version": "1.0.2"
}
14 changes: 9 additions & 5 deletions custom_components/tibber_local/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""Platform for Senec sensors."""
import logging

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
Expand All @@ -14,10 +13,12 @@
)

_LOGGER = logging.getLogger(__name__)
_LANG = None

async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities):
"""Initialize sensor platform from config entry."""
coordinator = hass.data[DOMAIN][config_entry.entry_id]
global _LANG
_LANG = coordinator.lang
entities = []
for description in SENSOR_TYPES:
entity = TibberLocalSensor(coordinator, description)
Expand All @@ -27,8 +28,6 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry,


class TibberLocalSensor(TibberLocalEntity, SensorEntity):
"""Sensor for the single values (e.g. pv power, ac power)."""

def __init__(
self,
coordinator: TibberLocalDataUpdateCoordinator,
Expand All @@ -45,7 +44,12 @@ def __init__(
key = self.entity_description.key.lower()
name = self.entity_description.name
self.entity_id = f"sensor.{slugify(title)}_{key}"
self._attr_name = f"{name}"
if key in _LANG:
self._attr_name = _LANG[key]
else:
_LOGGER.warning(str(key)+" Sensor not found in translation")
self._attr_name = f"{name}"

if hasattr(description, 'suggested_display_precision') and description.suggested_display_precision is not None:
self._attr_suggested_display_precision = description.suggested_display_precision
else:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tibber_local/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"data": {
"name": "Anzeige Name",
"host": "IP oder Hostname der Tibber Pulse Bridge",
"password": "Das Bridge Passwort - [Du findest das Passwort of der Tibber Bridge - unter dem QR-Code]",
"password": "Das Bridge Passwort - [Du findest das Passwort auf der Tibber Bridge - unter dem QR-Code]",
"scan_interval":"Aktualisierungsintervall in Sekunden"
}
}
Expand All @@ -28,7 +28,7 @@
"data": {
"name": "Anzeige Name",
"host": "IP oder Hostname der Tibber Pulse Bridge",
"password": "Das Bridge Passwort - [Du findest das Passwort of der Tibber Bridge - unter dem QR-Code]",
"password": "Das Bridge Passwort - [Du findest das Passwort auf der Tibber Bridge - unter dem QR-Code]",
"scan_interval":"Aktualisierungsintervall in Sekunden"
}
}
Expand Down
22 changes: 22 additions & 0 deletions custom_components/tibber_local/translations/local.de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"0100010800ff": "Zählerstand Total",
"0100020800ff": "Wirkenergie Total",
"0100010800ff_in_k": "Zählerstand Total (kWh)",
"0100020800ff_in_k": "Wirkenergie Total (kWh)",
"0100100700ff": "aktuelle Wirkleistung",
"0100240700ff": "Wirkleistung L1",
"0100380700ff": "Wirkleistung L2",
"01004c0700ff": "Wirkleistung L3",
"0100200700ff": "Spannung L1",
"0100340700ff": "Spannung L2",
"0100480700ff": "Spannung L3",
"01001f0700ff": "Strom L1",
"0100330700ff": "Strom L2",
"0100470700ff": "Strom L3",
"01000e0700ff": "Netz Frequenz",
"0100510701ff": "Phasenabweichung Spannungen L1/L2",
"0100510702ff": "Phasenabweichung Spannungen L1/L3",
"0100510704ff": "Phasenabweichung Strom/Spannung L1",
"010051070fff": "Phasenabweichung Strom/Spannung L2",
"010051071aff": "Phasenabweichung Strom/Spannung L3"
}
22 changes: 22 additions & 0 deletions custom_components/tibber_local/translations/local.en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"0100010800ff": "Import total",
"0100020800ff": "Export total",
"0100010800ff_in_k": "Import total (kWh)",
"0100020800ff_in_k": "Export total (kWh)",
"0100100700ff": "Power (actual)",
"0100240700ff": "Power L1",
"0100380700ff": "Power L2",
"01004c0700ff": "Power L3",
"0100200700ff": "Potential L1",
"0100340700ff": "Potential L2",
"0100480700ff": "Potential L3",
"01001f0700ff": "Current L1",
"0100330700ff": "Current L2",
"0100470700ff": "Current L3",
"01000e0700ff": "Net frequency",
"0100510701ff": "Potential Phase deviation L1/L2",
"0100510702ff": "Potential Phase deviation L1/L3",
"0100510704ff": "Current/Potential L1 Phase deviation",
"010051070fff": "Current/Potential L2 Phase deviation",
"010051071aff": "Current/Potential L3 Phase deviation"
}

0 comments on commit b62b34c

Please sign in to comment.