Skip to content

Commit 24269e3

Browse files
committed
adjust error/warning logic and translations
1 parent 6d7bd9f commit 24269e3

File tree

6 files changed

+94
-84
lines changed

6 files changed

+94
-84
lines changed

custom_components/bwt_perla/sensors/base.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
from datetime import datetime
33

4+
import logging
5+
46
from bwt_api.api import treated_to_blended
57
from bwt_api.data import BwtStatus
68

@@ -19,9 +21,13 @@
1921
from homeassistant.helpers.update_coordinator import CoordinatorEntity
2022
from homeassistant.helpers import translation
2123

24+
from ..util import truncate_value
25+
2226
from ..const import DOMAIN
2327
from ..coordinator import BwtCoordinator
2428

29+
_LOGGER = logging.getLogger(__name__)
30+
2531
_FAUCET = "mdi:faucet"
2632
_WATER = "mdi:water"
2733
_WARNING = "mdi:alert-circle"
@@ -156,7 +162,9 @@ def _update_values(self, errors) -> None:
156162
# Translate error names for display
157163
if errors:
158164
translated = [self._translate_code(x.name) for x in errors]
159-
self._attr_native_value = ", ".join(translated)
165+
# Join translated parts and ensure it does not exceed 255 chars
166+
joined = ", ".join(translated)
167+
self._attr_native_value = truncate_value(joined, 255)
160168
else:
161169
self._attr_native_value = ""
162170

@@ -195,11 +203,10 @@ def _update_values(self, warnings) -> None:
195203
self._attr_extra_state_attributes = {"warning_codes": raw_values}
196204

197205
# Translate warning names for display
198-
if warnings:
199-
translated = [self._translate_code(x.name) for x in warnings]
200-
self._attr_native_value = ", ".join(translated)
201-
else:
202-
self._attr_native_value = ""
206+
translated = [self._translate_code(x.name) for x in warnings]
207+
# Join translated parts and ensure it does not exceed 255 chars
208+
joined = ", ".join(translated)
209+
self._attr_native_value = truncate_value(joined, 255)
203210

204211
@callback
205212
def _handle_coordinator_update(self) -> None:

custom_components/bwt_perla/strings.json

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
11
{
22
"config": {
3+
"abort": {
4+
"already_configured": "Device is already configured"
5+
},
6+
"error": {
7+
"cannot_connect": "Failed to connect",
8+
"invalid_code_or_api_disabled": "Invalid code or local API not enabled. Please check: 1) Device firmware is version 2.02xx or later, 2) Local API is enabled in device Settings > General > Connection, 3) Login code is correct (sent via email during registration)",
9+
"unknown": "Unexpected error"
10+
},
311
"step": {
412
"user": {
513
"data": {
6-
"host": "[%key:common::config_flow::data::host%]",
7-
"code": "User-Code"
14+
"code": "User-Code",
15+
"host": "Host"
816
}
917
}
10-
},
11-
"error": {
12-
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
13-
"invalid_code_or_api_disabled": "Invalid code or local API not enabled. Please check: 1) Device firmware is version 2.02xx or later, 2) Local API is enabled in device Settings > General > Connection, 3) Login code is correct (sent via email during registration)",
14-
"unknown": "[%key:common::config_flow::error::unknown%]"
15-
},
16-
"abort": {
17-
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
1818
}
1919
},
2020
"entity": {
2121
"sensor": {
22-
"regenerativ_mass": {
23-
"name": "Total regeneration salt ever used"
24-
},
25-
"regenerativ_days": {
26-
"name": "Days left of regeneration salt"
27-
},
28-
"regenerativ_level": {
29-
"name": "Precentage of regeneration salt"
22+
"capacity_1": {
23+
"name": "Remaining capacity of column 1"
3024
},
31-
"state": {
32-
"name": "State of the machine"
25+
"capacity_2": {
26+
"name": "Remaining capacity of column 1"
3327
},
34-
"errors": {
35-
"name": "Active errors"
28+
"counter_regeneration_1": {
29+
"name": "Regeneration counter column 1"
3630
},
37-
"warnings": {
38-
"name": "Active warnings"
31+
"counter_regeneration_2": {
32+
"name": "Regeneration counter column 2"
3933
},
40-
"technician_service": {
41-
"name": "Last service by technician"
34+
"current_flow": {
35+
"name": "Current flow"
4236
},
4337
"customer_service": {
4438
"name": "Last service by customer"
4539
},
46-
"hardness_out": {
47-
"name": "Outgoing water hardness"
40+
"day_output": {
41+
"name": "Output of current day"
42+
},
43+
"errors": {
44+
"name": "Active errors"
4845
},
4946
"hardness_in": {
5047
"name": "Incoming water hardness"
5148
},
52-
"total_output": {
53-
"name": "Total water consumption"
49+
"hardness_out": {
50+
"name": "Outgoing water hardness"
5451
},
5552
"holiday_mode_start": {
5653
"name": "Future start of holiday mode if available"
5754
},
58-
"counter_regeneration_1": {
59-
"name": "Regeneration counter column 1"
60-
},
61-
"counter_regeneration_2": {
62-
"name": "Regeneration counter column 2"
63-
},
6455
"last_regeneration_1": {
6556
"name": "Last regeneration column 1"
6657
},
6758
"last_regeneration_2": {
6859
"name": "Last regeneration column 2"
6960
},
70-
"capacity_1": {
71-
"name": "Remaining capacity of column 1"
61+
"month_output": {
62+
"name": "Output of current month"
7263
},
73-
"capacity_2": {
74-
"name": "Remaining capacity of column 2"
64+
"regenerativ_days": {
65+
"name": "Days left of regeneration salt"
7566
},
76-
"day_output": {
77-
"name": "Output of current day"
67+
"regenerativ_level": {
68+
"name": "Percentage of regeneration salt"
7869
},
79-
"month_output": {
80-
"name": "Output of current month"
70+
"regenerativ_mass": {
71+
"name": "Total regeneration salt ever used"
72+
},
73+
"state": {
74+
"name": "State of the machine"
75+
},
76+
"technician_service": {
77+
"name": "Last service by technician"
78+
},
79+
"total_output": {
80+
"name": "Total water consumption"
81+
},
82+
"warnings": {
83+
"name": "Active warnings"
8184
},
8285
"year_output": {
8386
"name": "Output of current year"
8487
},
85-
"current_flow": {
86-
"name": "Current flow"
87-
},
8888
"holiday_mode": {
8989
"name": "Holiday mode active"
9090
},
@@ -110,7 +110,7 @@
110110
"offline_motor_1": "Motor 1 offline",
111111
"offline_motor_2": "Motor 2 offline",
112112
"offline_motor_blend": "Blend motor offline",
113-
"regenerativ_20": "Regeneration salt level at 20%",
113+
"regenerativ_20": "Regeneration salt level < 20%",
114114
"overcurrent_motor_1": "Overcurrent motor 1",
115115
"overcurrent_motor_2": "Overcurrent motor 2",
116116
"overcurrent_motor_3": "Overcurrent motor 3",
@@ -119,14 +119,14 @@
119119
"stop_sensor": "Stop sensor",
120120
"constant_flow": "Constant flow",
121121
"low_pressure": "Low pressure",
122-
"piston_position": "Piston position error",
123-
"electronic": "Electronic error",
122+
"piston_position": "Piston position",
123+
"electronic": "Electronic",
124124
"insufficient_regenerativ": "Insufficient regeneration salt",
125125
"stop_wireless_sensor": "Stop wireless sensor",
126126
"regenerativ_0": "Regeneration salt empty",
127-
"maintenance_customer": "Customer maintenance required",
127+
"maintenance_customer": "Routine maintenance due",
128128
"inspection_customer": "Customer inspection required",
129-
"maintenance_service": "Service maintenance required",
129+
"maintenance_service": "Technician maintenance due",
130130
"minerals_low": "Minerals low",
131131
"minerals_0": "Minerals empty",
132132
"overcurrent_valve_1": "Overcurrent valve 1",
@@ -135,10 +135,10 @@
135135
"overcurrent_valve_ball": "Overcurrent ball valve",
136136
"meter_not_counting": "Water meter not counting",
137137
"regeneration_drain": "Regeneration drain issue",
138-
"init_pcb_0": "PCB initialization error 0",
139-
"init_pcb_1": "PCB initialization error 1",
140-
"position_motor_1": "Motor 1 position error",
141-
"position_motor_2": "Motor 2 position error",
138+
"init_pcb_0": "PCB initialization 0",
139+
"init_pcb_1": "PCB initialization 1",
140+
"position_motor_1": "Motor 1 position",
141+
"position_motor_2": "Motor 2 position",
142142
"conductivity_high": "Conductivity too high",
143143
"conductivity_limit_1": "Conductivity limit 1 exceeded",
144144
"conductivity_limit_2": "Conductivity limit 2 exceeded",

custom_components/bwt_perla/translations/de.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"offline_motor_1": "Motor 1 offline",
111111
"offline_motor_2": "Motor 2 offline",
112112
"offline_motor_blend": "Mischmotor offline",
113-
"regenerativ_20": "Regeneriersalz-Stand bei 20%",
113+
"regenerativ_20": "Regeneriersalz-Stand < 20%",
114114
"overcurrent_motor_1": "Überstrom Motor 1",
115115
"overcurrent_motor_2": "Überstrom Motor 2",
116116
"overcurrent_motor_3": "Überstrom Motor 3",
@@ -126,7 +126,7 @@
126126
"regenerativ_0": "Regeneriersalz leer",
127127
"maintenance_customer": "Kundenwartung erforderlich",
128128
"inspection_customer": "Kundeninspektion erforderlich",
129-
"maintenance_service": "Servicewartung erforderlich",
129+
"maintenance_service": "Technikerwartung erforderlich",
130130
"minerals_low": "Mineralien niedrig",
131131
"minerals_0": "Mineralien leer",
132132
"overcurrent_valve_1": "Überstrom Ventil 1",
@@ -135,8 +135,8 @@
135135
"overcurrent_valve_ball": "Überstrom Kugelventil",
136136
"meter_not_counting": "Wasserzähler zählt nicht",
137137
"regeneration_drain": "Regenerationsabfluss-Problem",
138-
"init_pcb_0": "Leiterplatten-Initialisierungsfehler 0",
139-
"init_pcb_1": "Leiterplatten-Initialisierungsfehler 1",
138+
"init_pcb_0": "PCB-Initialisierungsfehler 0",
139+
"init_pcb_1": "PCB-Initialisierungsfehler 1",
140140
"position_motor_1": "Positionsfehler Motor 1",
141141
"position_motor_2": "Positionsfehler Motor 2",
142142
"conductivity_high": "Leitfähigkeit zu hoch",

custom_components/bwt_perla/translations/en.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"name": "Days left of regeneration salt"
6666
},
6767
"regenerativ_level": {
68-
"name": "Precentage of regeneration salt"
68+
"name": "Percentage of regeneration salt"
6969
},
7070
"regenerativ_mass": {
7171
"name": "Total regeneration salt ever used"
@@ -110,7 +110,7 @@
110110
"offline_motor_1": "Motor 1 offline",
111111
"offline_motor_2": "Motor 2 offline",
112112
"offline_motor_blend": "Blend motor offline",
113-
"regenerativ_20": "Regeneration salt level at 20%",
113+
"regenerativ_20": "Regeneration salt level < 20%",
114114
"overcurrent_motor_1": "Overcurrent motor 1",
115115
"overcurrent_motor_2": "Overcurrent motor 2",
116116
"overcurrent_motor_3": "Overcurrent motor 3",
@@ -119,14 +119,14 @@
119119
"stop_sensor": "Stop sensor",
120120
"constant_flow": "Constant flow",
121121
"low_pressure": "Low pressure",
122-
"piston_position": "Piston position error",
123-
"electronic": "Electronic error",
122+
"piston_position": "Piston position",
123+
"electronic": "Electronic",
124124
"insufficient_regenerativ": "Insufficient regeneration salt",
125125
"stop_wireless_sensor": "Stop wireless sensor",
126126
"regenerativ_0": "Regeneration salt empty",
127-
"maintenance_customer": "Customer maintenance required",
127+
"maintenance_customer": "Routine maintenance due",
128128
"inspection_customer": "Customer inspection required",
129-
"maintenance_service": "Service maintenance required",
129+
"maintenance_service": "Technician maintenance due",
130130
"minerals_low": "Minerals low",
131131
"minerals_0": "Minerals empty",
132132
"overcurrent_valve_1": "Overcurrent valve 1",
@@ -135,10 +135,10 @@
135135
"overcurrent_valve_ball": "Overcurrent ball valve",
136136
"meter_not_counting": "Water meter not counting",
137137
"regeneration_drain": "Regeneration drain issue",
138-
"init_pcb_0": "PCB initialization error 0",
139-
"init_pcb_1": "PCB initialization error 1",
140-
"position_motor_1": "Motor 1 position error",
141-
"position_motor_2": "Motor 2 position error",
138+
"init_pcb_0": "PCB initialization 0",
139+
"init_pcb_1": "PCB initialization 1",
140+
"position_motor_1": "Motor 1 position",
141+
"position_motor_2": "Motor 2 position",
142142
"conductivity_high": "Conductivity too high",
143143
"conductivity_limit_1": "Conductivity limit 1 exceeded",
144144
"conductivity_limit_2": "Conductivity limit 2 exceeded",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def truncate_value(value: str, max_length: int = 255) -> str:
2+
"""Truncate a string to `max_length` characters, adding ellipsis if needed.
3+
4+
Returns an empty string for None-like inputs and ensures a string is returned
5+
even if the input cannot be converted to `str`.
6+
"""
7+
if value is None:
8+
return ""
9+
if len(value) <= max_length:
10+
return value
11+
return value[: max_length - 3] + "..."

dev/configuration.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
# Loads default set of integrations. Do not remove.
33
default_config:
44

5-
# Load frontend themes from the themes folder
6-
frontend:
7-
themes: !include_dir_merge_named themes
8-
9-
automation: !include automations.yaml
10-
script: !include scripts.yaml
11-
scene: !include scenes.yaml
12-
135
logger:
146
default: info
157
logs:

0 commit comments

Comments
 (0)