Skip to content

Commit

Permalink
feat: Translated device names
Browse files Browse the repository at this point in the history
  • Loading branch information
alepee committed Nov 23, 2024
1 parent babbbb5 commit 0ec76f7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 31 deletions.
63 changes: 33 additions & 30 deletions custom_components/hitachi_yutaki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.translation import async_get_translations

from .const import (
DOMAIN,
Expand Down Expand Up @@ -50,13 +51,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Register devices
device_registry = dr.async_get(hass)

# Get translations for device names
translations = await async_get_translations(
hass,
hass.config.language,
"device",
DOMAIN
)

def get_translated_name(device_key: str, fallback: str) -> str:
"""Get translated name for device with fallback."""
return translations.get(f"device.{device_key}.name", fallback)

# Add gateway device
gateway_name = get_translated_name("gateway", DEVICE_GATEWAY.title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_GATEWAY}")},
manufacturer="Hitachi",
model="ATW-MBS-02",
name=DEVICE_GATEWAY.title(),
name=gateway_name,
configuration_url=f"http://{entry.data[CONF_HOST]}",
)

Expand All @@ -65,95 +79,84 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
model_name = MODEL_NAMES.get(unit_model, "Unknown Model")

# Add main unit device
control_unit_name = get_translated_name("control_unit", DEVICE_CONTROL_UNIT.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}")},
manufacturer="Hitachi",
model=model_name,
name=DEVICE_CONTROL_UNIT.replace("_", " ").title(),
name=control_unit_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_GATEWAY}"),
)

# Add primary compressor device
primary_compressor_name = get_translated_name("primary_compressor", DEVICE_PRIMARY_COMPRESSOR.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_PRIMARY_COMPRESSOR}")},
manufacturer="Hitachi",
model=model_name,
name=DEVICE_PRIMARY_COMPRESSOR.replace("_", " ").title(),
name=primary_compressor_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}"),
)

# Add secondary compressor device for S80 model
if coordinator.is_s80_model():
secondary_compressor_name = get_translated_name("secondary_compressor", DEVICE_SECONDARY_COMPRESSOR.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_SECONDARY_COMPRESSOR}")},
manufacturer="Hitachi",
model=model_name,
name=DEVICE_SECONDARY_COMPRESSOR.replace("_", " ").title(),
name=secondary_compressor_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}"),
)

# Add Circuit 1 device if configured
if coordinator.has_heating_circuit1() or coordinator.has_cooling_circuit1():
features = []
if coordinator.has_heating_circuit1():
features.append("Heating")
if coordinator.has_cooling_circuit1():
features.append("Cooling")

device_name = DEVICE_CIRCUIT_1.replace("_", " ").title()
circuit1_name = get_translated_name("circuit1", DEVICE_CIRCUIT_1.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_CIRCUIT_1}")},
manufacturer="Hitachi",
model=f"{model_name} {device_name}",
name=device_name,
model=f"{model_name} {circuit1_name}",
name=circuit1_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}"),
)

# Add Circuit 2 device if configured
if coordinator.has_heating_circuit2() or coordinator.has_cooling_circuit2():
features = []
if coordinator.has_heating_circuit2():
features.append("Heating")
if coordinator.has_cooling_circuit2():
features.append("Cooling")

device_name = DEVICE_CIRCUIT_2.replace("_", " ").title()
circuit2_name = get_translated_name("circuit2", DEVICE_CIRCUIT_2.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_CIRCUIT_2}")},
manufacturer="Hitachi",
model=f"{model_name} {device_name}",
name=device_name,
model=f"{model_name} {circuit2_name}",
name=circuit2_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}"),
)

# Add DHW device if configured
if coordinator.has_dhw():
device_name = DEVICE_DHW.replace("_", " ").title()

dhw_name = get_translated_name("dhw_heater", DEVICE_DHW.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_DHW}")},
manufacturer="Hitachi",
model=f"{model_name} {device_name}",
name=device_name,
model=f"{model_name} {dhw_name}",
name=dhw_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}"),
)

# Add Pool device if configured
if coordinator.has_pool():
device_name = DEVICE_POOL.replace("_", " ").title()

pool_name = get_translated_name("pool", DEVICE_POOL.replace("_", " ").title())
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, f"{entry.entry_id}_{DEVICE_POOL}")},
manufacturer="Hitachi",
model=f"{model_name} {device_name}",
name=device_name,
model=f"{model_name} {pool_name}",
name=pool_name,
via_device=(DOMAIN, f"{entry.entry_id}_{DEVICE_CONTROL_UNIT}"),
)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hitachi_yutaki/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# Modbus registers (addresses)
REGISTER_UNIT_MODEL = 1218
REGISTER_CENTRAL_CONTROL_MODE = 1088
REGISTER_SYSTEM_CONFIG = 1089
REGISTER_SYSTEM_STATUS = 1222

Expand Down Expand Up @@ -146,7 +147,6 @@
"auto": 2,
}

REGISTER_CENTRAL_CONTROL_MODE = 1088
CENTRAL_CONTROL_MODE_MAP = {
"local": 0,
"air": 1,
Expand Down
26 changes: 26 additions & 0 deletions custom_components/hitachi_yutaki/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
{
"device": {
"gateway": {
"name": "Gateway"
},
"control_unit": {
"name": "Control Unit"
},
"primary_compressor": {
"name": "Outdoor Compressor"
},
"secondary_compressor": {
"name": "Indoor Compressor"
},
"circuit1": {
"name": "Circuit 1"
},
"circuit2": {
"name": "Circuit 2"
},
"dhw": {
"name": "DHW"
},
"pool": {
"name": "Pool"
}
},
"config": {
"step": {
"user": {
Expand Down
26 changes: 26 additions & 0 deletions custom_components/hitachi_yutaki/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
{
"device": {
"gateway": {
"name": "Passerelle"
},
"control_unit": {
"name": "Unité de Contrôle"
},
"primary_compressor": {
"name": "Compresseur Extérieur"
},
"secondary_compressor": {
"name": "Compresseur Intérieur"
},
"circuit1": {
"name": "Circuit 1"
},
"circuit2": {
"name": "Circuit 2"
},
"dhw": {
"name": "ECS"
},
"pool": {
"name": "Piscine"
}
},
"config": {
"step": {
"user": {
Expand Down

0 comments on commit 0ec76f7

Please sign in to comment.