Skip to content

Commit

Permalink
Add localization and internationalization support (#42)
Browse files Browse the repository at this point in the history
* Replace `Busy` state with  beverage specific brewing state. Close #38

* Add i18n support
  • Loading branch information
TillFleisch committed Mar 7, 2024
1 parent 2bcf577 commit 866fb17
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 63 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ A example configuration can be found [here](example.yaml)
- **invert_power_pin**(**Optional**: boolean): If set to `true` the output of the power pin will be inverted. Defaults to `false`.
- **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`.
- **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`.
- **language**(**Optional**: int): Status sensor language. Select one of `en-US`, `de-DE`. Defaults to `en-US`.
- **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`.

## Philips Power switch
Expand Down
9 changes: 9 additions & 0 deletions components/philips_coffee_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"EP_3246": "PHILIPS_EP3243",
}

CONF_LANGUAGE = "language"
# Using IETF BCP 47 language tags (RFC 5646)
LANGUAGES = {
"en-US": "PHILIPS_COFFEE_LANG_en_US",
"de-DE": "PHILIPS_COFFEE_LANG_de_DE",
}

philips_coffee_machine_ns = cg.esphome_ns.namespace("philips_coffee_machine")
PhilipsCoffeeMachine = philips_coffee_machine_ns.class_(
"PhilipsCoffeeMachine", cg.Component
Expand All @@ -46,13 +53,15 @@
cv.Optional(CONF_COMMAND_SET, default="EP_2220"): cv.enum(
COMMAND_SETS, upper=True, space="_"
),
cv.Optional(CONF_LANGUAGE, default="en-US"): cv.enum(LANGUAGES, space="-"),
}
).extend(cv.COMPONENT_SCHEMA)


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

var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
Expand Down
110 changes: 110 additions & 0 deletions components/philips_coffee_machine/localization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#pragma once
#include <string>

namespace esphome
{
namespace philips_coffee_machine
{
#if defined(PHILIPS_COFFEE_LANG_en_US)
#define PHILIPS_COFFEE_LANG_DEFAULT
#elif defined(PHILIPS_COFFEE_LANG_de_DE)
const std::string state_unknown = "Unbekannt";
const std::string state_off = "Aus";
const std::string state_idle = "Bereit";
const std::string state_cleaning = "Spült";
const std::string state_preparing = "Vorbereitung";
const std::string state_water_empty = "Wasser leer";
const std::string state_waste_warning = "Abfallcontainerwarnung";
const std::string state_error = "Fehler";

const std::string state_ground_coffee_selected = "Vorgemahlener Kaffee ausgewählt";
const std::string state_coffee_programming_mode = "Kaffee Programmiermodus ausgewählt";
const std::string state_coffee_selected = "Kaffee ausgewählt";
const std::string state_coffee_2x_selected = "2x Kaffee ausgewählt";
const std::string state_coffee_brewing = "Bereitet Kaffee zu";
const std::string state_coffee_2x_brewing = "Bereitet 2x Kaffee zu";

const std::string state_ground_espresso_selected = "Vorgemahlener Espresso ausgewählt";
const std::string state_espresso_programming_mode = "Espresso Programmiermodus ausgewählt";
const std::string state_espresso_selected = "Espresso ausgewählt";
const std::string state_espresso_2x_selected = "2x Espresso ausgewählt";
const std::string state_espresso_brewing = "Bereitet Espresso zu";
const std::string state_espresso_2x_brewing = "Bereitet 2x Espresso zu";

const std::string state_ground_americano_selected = "Vorgemahlener Americano ausgewählt";
const std::string state_americano_programming_mode = "Americano Programmiermodus ausgewählt";
const std::string state_americano_selected = "Americano ausgewählt";
const std::string state_americano_2x_selected = "2x Americano ausgewählt";
const std::string state_americano_brewing = "Bereitet Americano zu";
const std::string state_americano_2x_brewing = "Bereitet 2x Americano zu";

const std::string state_ground_cappuccino_selected = "Vorgemahlener Cappuccino ausgewählt";
const std::string state_cappuccino_programming_mode = "Cappuccino Programmiermodus ausgewählt";
const std::string state_cappuccino_selected = "Cappuccino ausgewählt";
const std::string state_cappuccino_brewing = "Bereitet Cappuccino zu";

const std::string state_ground_latte_selected = "Vorgemahlener Latte macchiato ausgewählt";
const std::string state_latte_programming_mode = "Latte macchiato Programmiermodus ausgewählt";
const std::string state_latte_selected = "Latte macchiato ausgewählt";
const std::string state_latte_brewing = "Bereitet Latte macchiato zu";

const std::string state_hot_water_programming_mode = "Heißes Wasser Programmiermodus ausgewählt";
const std::string state_hot_water_selected = "Heißes Wasser ausgewählt";
const std::string state_hot_water_brewing = "Bereitet heißes Wasser zu";

const std::string state_steam_selected = "Dampf ausgewählt";
const std::string state_steam_brewing = "Bereitet Dampf zu";
#else
#define PHILIPS_COFFEE_LANG_DEFAULT
#endif

#ifdef PHILIPS_COFFEE_LANG_DEFAULT
const std::string state_unknown = "Unknown";
const std::string state_off = "Off";
const std::string state_idle = "Idle";
const std::string state_cleaning = "Cleaning";
const std::string state_preparing = "Preparing";
const std::string state_water_empty = "Water empty";
const std::string state_waste_warning = "Waste container warning";
const std::string state_error = "Error";

const std::string state_ground_coffee_selected = "Pre-ground Coffee selected";
const std::string state_coffee_programming_mode = "Coffee programming mode selected";
const std::string state_coffee_selected = "Coffee selected";
const std::string state_coffee_2x_selected = "2x Coffee selected";
const std::string state_coffee_brewing = "Brewing Coffee";
const std::string state_coffee_2x_brewing = "Brewing 2x Coffee";

const std::string state_ground_espresso_selected = "Pre-ground Espresso selected";
const std::string state_espresso_programming_mode = "Espresso programming mode selected";
const std::string state_espresso_selected = "Espresso selected";
const std::string state_espresso_2x_selected = "2x Espresso selected";
const std::string state_espresso_brewing = "Brewing Espresso";
const std::string state_espresso_2x_brewing = "Brewing 2x Espresso";

const std::string state_ground_americano_selected = "Pre-ground Americano selected";
const std::string state_americano_programming_mode = "Americano programming mode selected";
const std::string state_americano_selected = "Americano selected";
const std::string state_americano_2x_selected = "2x Americano selected";
const std::string state_americano_brewing = "Brewing Americano";
const std::string state_americano_2x_brewing = "Brewing 2x Americano";

const std::string state_ground_cappuccino_selected = "Pre-ground Cappuccino selected";
const std::string state_cappuccino_programming_mode = "Cappuccino programming mode selected";
const std::string state_cappuccino_selected = "Cappuccino selected";
const std::string state_cappuccino_brewing = "Brewing Cappuccino";

const std::string state_ground_latte_selected = "Pre-ground Latte Macchiato selected";
const std::string state_latte_programming_mode = "Latte Macchiato programming mode selected";
const std::string state_latte_selected = "Latte Macchiato selected";
const std::string state_latte_brewing = "Brewing Latte Macchiato";

const std::string state_hot_water_programming_mode = "Hot water programming mode selected";
const std::string state_hot_water_selected = "Hot water selected";
const std::string state_hot_water_brewing = "Making Hot Water";

const std::string state_steam_selected = "Steam selected";
const std::string state_steam_brewing = "Making Steam";
#endif
} // namespace philips_coffee_machine
} // namespace esphome
28 changes: 14 additions & 14 deletions components/philips_coffee_machine/number/beverage_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ namespace esphome
// only apply status if source is currently selected
std::string status = status_sensor_->get_raw_state();
if ((type_ != MILK && (source_ == COFFEE || source_ == ANY) &&
(status.compare("Coffee selected") == 0 ||
status.compare("2x Coffee selected") == 0 ||
(type_ != BEAN && status.compare("Ground Coffee selected") == 0))) ||
(status.compare(state_coffee_selected) == 0 ||
status.compare(state_coffee_2x_selected) == 0 ||
(type_ != BEAN && status.compare(state_ground_coffee_selected) == 0))) ||
(type_ != MILK && (source_ == ESPRESSO || source_ == ANY) &&
(status.compare("Espresso selected") == 0 ||
status.compare("2x Espresso selected") == 0 ||
(type_ != BEAN && status.compare("Ground Espresso selected") == 0))) ||
(status.compare(state_espresso_selected) == 0 ||
status.compare(state_espresso_2x_selected) == 0 ||
(type_ != BEAN && status.compare(state_ground_espresso_selected) == 0))) ||
(type_ != MILK && (source_ == AMERICANO || source_ == ANY) &&
(status.compare("Americano selected") == 0 ||
status.compare("2x Americano selected") == 0 ||
(type_ != BEAN && status.compare("Ground Americano selected") == 0))) ||
(status.compare(state_americano_selected) == 0 ||
status.compare(state_americano_2x_selected) == 0 ||
(type_ != BEAN && status.compare(state_ground_americano_selected) == 0))) ||
((source_ == CAPPUCCINO || source_ == ANY) &&
(status.compare("Cappuccino selected") == 0 ||
(type_ != BEAN && status.compare("Ground Cappuccino selected") == 0))) ||
(status.compare(state_cappuccino_selected) == 0 ||
(type_ != BEAN && status.compare(state_ground_cappuccino_selected) == 0))) ||
((source_ == LATTE_MACCHIATO || source_ == ANY) &&
(status.compare("Latte Macchiato selected") == 0 ||
(type_ != BEAN && status.compare("Ground Latte Macchiato selected") == 0))) ||
(status.compare(state_latte_selected) == 0 ||
(type_ != BEAN && status.compare(state_ground_latte_selected) == 0))) ||
(type_ != BEAN && type_ != MILK && (source_ == HOT_WATER || source_ == ANY) &&
status.compare("Hot water selected") == 0))
status.compare(state_hot_water_selected) == 0))
{
uint8_t enable_byte = type_ == BEAN ? 9 : 11;
uint8_t amount_byte = type_ == BEAN ? 8 : (type_ == SIZE ? 10 : 13);
Expand Down
Loading

0 comments on commit 866fb17

Please sign in to comment.