diff --git a/custom_components/hitachi_yutaki/__init__.py b/custom_components/hitachi_yutaki/__init__.py index a035ae8..a7c8e20 100644 --- a/custom_components/hitachi_yutaki/__init__.py +++ b/custom_components/hitachi_yutaki/__init__.py @@ -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, @@ -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]}", ) @@ -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}"), ) diff --git a/custom_components/hitachi_yutaki/const.py b/custom_components/hitachi_yutaki/const.py index c0debfa..5c85a44 100644 --- a/custom_components/hitachi_yutaki/const.py +++ b/custom_components/hitachi_yutaki/const.py @@ -25,6 +25,7 @@ # Modbus registers (addresses) REGISTER_UNIT_MODEL = 1218 +REGISTER_CENTRAL_CONTROL_MODE = 1088 REGISTER_SYSTEM_CONFIG = 1089 REGISTER_SYSTEM_STATUS = 1222 @@ -146,7 +147,6 @@ "auto": 2, } -REGISTER_CENTRAL_CONTROL_MODE = 1088 CENTRAL_CONTROL_MODE_MAP = { "local": 0, "air": 1, diff --git a/custom_components/hitachi_yutaki/translations/en.json b/custom_components/hitachi_yutaki/translations/en.json index bc87059..6c54b7c 100644 --- a/custom_components/hitachi_yutaki/translations/en.json +++ b/custom_components/hitachi_yutaki/translations/en.json @@ -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": { diff --git a/custom_components/hitachi_yutaki/translations/fr.json b/custom_components/hitachi_yutaki/translations/fr.json index 6cf97fb..4f1acda 100644 --- a/custom_components/hitachi_yutaki/translations/fr.json +++ b/custom_components/hitachi_yutaki/translations/fr.json @@ -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": {