Skip to content

Commit 866fb17

Browse files
authored
Add localization and internationalization support (#42)
* Replace `Busy` state with beverage specific brewing state. Close #38 * Add i18n support
1 parent 2bcf577 commit 866fb17

File tree

6 files changed

+210
-63
lines changed

6 files changed

+210
-63
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ A example configuration can be found [here](example.yaml)
2929
- **invert_power_pin**(**Optional**: boolean): If set to `true` the output of the power pin will be inverted. Defaults to `false`.
3030
- **power_trip_delay**(**Optional**: Time): Determines the length of the power outage applied to the display unit, which is to trick it into turning on. Defaults to `500ms`.
3131
- **power_message_repetitions**(**Optional**: uint): Determines how many message repetitions are used while turning on the machine. On some hardware combinations a higher value such as `25` is required to turn on the display successfully. Defaults to `5`.
32+
- **language**(**Optional**: int): Status sensor language. Select one of `en-US`, `de-DE`. Defaults to `en-US`.
3233
- **model**(**Optional**: int): Different models or revisions may use different commands. This option can be used to specify the command set used by this component. Select one of `EP_2220`, `EP_2235`, `EP_3243`, `EP_3246`. Defaults to `EP_2220`.
3334

3435
## Philips Power switch

components/philips_coffee_machine/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"EP_3246": "PHILIPS_EP3243",
2424
}
2525

26+
CONF_LANGUAGE = "language"
27+
# Using IETF BCP 47 language tags (RFC 5646)
28+
LANGUAGES = {
29+
"en-US": "PHILIPS_COFFEE_LANG_en_US",
30+
"de-DE": "PHILIPS_COFFEE_LANG_de_DE",
31+
}
32+
2633
philips_coffee_machine_ns = cg.esphome_ns.namespace("philips_coffee_machine")
2734
PhilipsCoffeeMachine = philips_coffee_machine_ns.class_(
2835
"PhilipsCoffeeMachine", cg.Component
@@ -46,13 +53,15 @@
4653
cv.Optional(CONF_COMMAND_SET, default="EP_2220"): cv.enum(
4754
COMMAND_SETS, upper=True, space="_"
4855
),
56+
cv.Optional(CONF_LANGUAGE, default="en-US"): cv.enum(LANGUAGES, space="-"),
4957
}
5058
).extend(cv.COMPONENT_SCHEMA)
5159

5260

5361
def to_code(config):
5462
# Use user-specified command set, default to EP_2200
5563
cg.add_define(COMMAND_SETS[config[CONF_COMMAND_SET]])
64+
cg.add_define(LANGUAGES[config[CONF_LANGUAGE]])
5665

5766
var = cg.new_Pvariable(config[CONF_ID])
5867
yield cg.register_component(var, config)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#pragma once
2+
#include <string>
3+
4+
namespace esphome
5+
{
6+
namespace philips_coffee_machine
7+
{
8+
#if defined(PHILIPS_COFFEE_LANG_en_US)
9+
#define PHILIPS_COFFEE_LANG_DEFAULT
10+
#elif defined(PHILIPS_COFFEE_LANG_de_DE)
11+
const std::string state_unknown = "Unbekannt";
12+
const std::string state_off = "Aus";
13+
const std::string state_idle = "Bereit";
14+
const std::string state_cleaning = "Spült";
15+
const std::string state_preparing = "Vorbereitung";
16+
const std::string state_water_empty = "Wasser leer";
17+
const std::string state_waste_warning = "Abfallcontainerwarnung";
18+
const std::string state_error = "Fehler";
19+
20+
const std::string state_ground_coffee_selected = "Vorgemahlener Kaffee ausgewählt";
21+
const std::string state_coffee_programming_mode = "Kaffee Programmiermodus ausgewählt";
22+
const std::string state_coffee_selected = "Kaffee ausgewählt";
23+
const std::string state_coffee_2x_selected = "2x Kaffee ausgewählt";
24+
const std::string state_coffee_brewing = "Bereitet Kaffee zu";
25+
const std::string state_coffee_2x_brewing = "Bereitet 2x Kaffee zu";
26+
27+
const std::string state_ground_espresso_selected = "Vorgemahlener Espresso ausgewählt";
28+
const std::string state_espresso_programming_mode = "Espresso Programmiermodus ausgewählt";
29+
const std::string state_espresso_selected = "Espresso ausgewählt";
30+
const std::string state_espresso_2x_selected = "2x Espresso ausgewählt";
31+
const std::string state_espresso_brewing = "Bereitet Espresso zu";
32+
const std::string state_espresso_2x_brewing = "Bereitet 2x Espresso zu";
33+
34+
const std::string state_ground_americano_selected = "Vorgemahlener Americano ausgewählt";
35+
const std::string state_americano_programming_mode = "Americano Programmiermodus ausgewählt";
36+
const std::string state_americano_selected = "Americano ausgewählt";
37+
const std::string state_americano_2x_selected = "2x Americano ausgewählt";
38+
const std::string state_americano_brewing = "Bereitet Americano zu";
39+
const std::string state_americano_2x_brewing = "Bereitet 2x Americano zu";
40+
41+
const std::string state_ground_cappuccino_selected = "Vorgemahlener Cappuccino ausgewählt";
42+
const std::string state_cappuccino_programming_mode = "Cappuccino Programmiermodus ausgewählt";
43+
const std::string state_cappuccino_selected = "Cappuccino ausgewählt";
44+
const std::string state_cappuccino_brewing = "Bereitet Cappuccino zu";
45+
46+
const std::string state_ground_latte_selected = "Vorgemahlener Latte macchiato ausgewählt";
47+
const std::string state_latte_programming_mode = "Latte macchiato Programmiermodus ausgewählt";
48+
const std::string state_latte_selected = "Latte macchiato ausgewählt";
49+
const std::string state_latte_brewing = "Bereitet Latte macchiato zu";
50+
51+
const std::string state_hot_water_programming_mode = "Heißes Wasser Programmiermodus ausgewählt";
52+
const std::string state_hot_water_selected = "Heißes Wasser ausgewählt";
53+
const std::string state_hot_water_brewing = "Bereitet heißes Wasser zu";
54+
55+
const std::string state_steam_selected = "Dampf ausgewählt";
56+
const std::string state_steam_brewing = "Bereitet Dampf zu";
57+
#else
58+
#define PHILIPS_COFFEE_LANG_DEFAULT
59+
#endif
60+
61+
#ifdef PHILIPS_COFFEE_LANG_DEFAULT
62+
const std::string state_unknown = "Unknown";
63+
const std::string state_off = "Off";
64+
const std::string state_idle = "Idle";
65+
const std::string state_cleaning = "Cleaning";
66+
const std::string state_preparing = "Preparing";
67+
const std::string state_water_empty = "Water empty";
68+
const std::string state_waste_warning = "Waste container warning";
69+
const std::string state_error = "Error";
70+
71+
const std::string state_ground_coffee_selected = "Pre-ground Coffee selected";
72+
const std::string state_coffee_programming_mode = "Coffee programming mode selected";
73+
const std::string state_coffee_selected = "Coffee selected";
74+
const std::string state_coffee_2x_selected = "2x Coffee selected";
75+
const std::string state_coffee_brewing = "Brewing Coffee";
76+
const std::string state_coffee_2x_brewing = "Brewing 2x Coffee";
77+
78+
const std::string state_ground_espresso_selected = "Pre-ground Espresso selected";
79+
const std::string state_espresso_programming_mode = "Espresso programming mode selected";
80+
const std::string state_espresso_selected = "Espresso selected";
81+
const std::string state_espresso_2x_selected = "2x Espresso selected";
82+
const std::string state_espresso_brewing = "Brewing Espresso";
83+
const std::string state_espresso_2x_brewing = "Brewing 2x Espresso";
84+
85+
const std::string state_ground_americano_selected = "Pre-ground Americano selected";
86+
const std::string state_americano_programming_mode = "Americano programming mode selected";
87+
const std::string state_americano_selected = "Americano selected";
88+
const std::string state_americano_2x_selected = "2x Americano selected";
89+
const std::string state_americano_brewing = "Brewing Americano";
90+
const std::string state_americano_2x_brewing = "Brewing 2x Americano";
91+
92+
const std::string state_ground_cappuccino_selected = "Pre-ground Cappuccino selected";
93+
const std::string state_cappuccino_programming_mode = "Cappuccino programming mode selected";
94+
const std::string state_cappuccino_selected = "Cappuccino selected";
95+
const std::string state_cappuccino_brewing = "Brewing Cappuccino";
96+
97+
const std::string state_ground_latte_selected = "Pre-ground Latte Macchiato selected";
98+
const std::string state_latte_programming_mode = "Latte Macchiato programming mode selected";
99+
const std::string state_latte_selected = "Latte Macchiato selected";
100+
const std::string state_latte_brewing = "Brewing Latte Macchiato";
101+
102+
const std::string state_hot_water_programming_mode = "Hot water programming mode selected";
103+
const std::string state_hot_water_selected = "Hot water selected";
104+
const std::string state_hot_water_brewing = "Making Hot Water";
105+
106+
const std::string state_steam_selected = "Steam selected";
107+
const std::string state_steam_brewing = "Making Steam";
108+
#endif
109+
} // namespace philips_coffee_machine
110+
} // namespace esphome

components/philips_coffee_machine/number/beverage_setting.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ namespace esphome
3535
// only apply status if source is currently selected
3636
std::string status = status_sensor_->get_raw_state();
3737
if ((type_ != MILK && (source_ == COFFEE || source_ == ANY) &&
38-
(status.compare("Coffee selected") == 0 ||
39-
status.compare("2x Coffee selected") == 0 ||
40-
(type_ != BEAN && status.compare("Ground Coffee selected") == 0))) ||
38+
(status.compare(state_coffee_selected) == 0 ||
39+
status.compare(state_coffee_2x_selected) == 0 ||
40+
(type_ != BEAN && status.compare(state_ground_coffee_selected) == 0))) ||
4141
(type_ != MILK && (source_ == ESPRESSO || source_ == ANY) &&
42-
(status.compare("Espresso selected") == 0 ||
43-
status.compare("2x Espresso selected") == 0 ||
44-
(type_ != BEAN && status.compare("Ground Espresso selected") == 0))) ||
42+
(status.compare(state_espresso_selected) == 0 ||
43+
status.compare(state_espresso_2x_selected) == 0 ||
44+
(type_ != BEAN && status.compare(state_ground_espresso_selected) == 0))) ||
4545
(type_ != MILK && (source_ == AMERICANO || source_ == ANY) &&
46-
(status.compare("Americano selected") == 0 ||
47-
status.compare("2x Americano selected") == 0 ||
48-
(type_ != BEAN && status.compare("Ground Americano selected") == 0))) ||
46+
(status.compare(state_americano_selected) == 0 ||
47+
status.compare(state_americano_2x_selected) == 0 ||
48+
(type_ != BEAN && status.compare(state_ground_americano_selected) == 0))) ||
4949
((source_ == CAPPUCCINO || source_ == ANY) &&
50-
(status.compare("Cappuccino selected") == 0 ||
51-
(type_ != BEAN && status.compare("Ground Cappuccino selected") == 0))) ||
50+
(status.compare(state_cappuccino_selected) == 0 ||
51+
(type_ != BEAN && status.compare(state_ground_cappuccino_selected) == 0))) ||
5252
((source_ == LATTE_MACCHIATO || source_ == ANY) &&
53-
(status.compare("Latte Macchiato selected") == 0 ||
54-
(type_ != BEAN && status.compare("Ground Latte Macchiato selected") == 0))) ||
53+
(status.compare(state_latte_selected) == 0 ||
54+
(type_ != BEAN && status.compare(state_ground_latte_selected) == 0))) ||
5555
(type_ != BEAN && type_ != MILK && (source_ == HOT_WATER || source_ == ANY) &&
56-
status.compare("Hot water selected") == 0))
56+
status.compare(state_hot_water_selected) == 0))
5757
{
5858
uint8_t enable_byte = type_ == BEAN ? 9 : 11;
5959
uint8_t amount_byte = type_ == BEAN ? 8 : (type_ == SIZE ? 10 : 13);

0 commit comments

Comments
 (0)