Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

把Climate实体也汉化 #18

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions custom_components/airtub_udp/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class AirtubClimateDevice(ClimateEntity):
def __init__(self, hass, name, mode):
"""Initialize the climate device."""
self._enable_turn_on_off_backwards_compatibility = False
self._name = name
self._unique_id = name
self._name = self._generate_friendly_name()
self._hass = hass
self._mode = mode
self._mode_set = False
Expand All @@ -65,19 +66,30 @@ def __init__(self, hass, name, mode):
)
self._disable_update = False

@property
def name(self):
"""Return the name of the climate device."""
return self._name
def _generate_friendly_name(self):
"""Generate a friendly name."""
if "_ch" in self._unique_id:
return "ch_control"
return "dhw_control"

@property
def unique_id(self):
"""Return the unique ID of the climate device."""
return self._unique_id

@property
def translation_key(self):
"""Return the translation key."""
return self._name

@property
def has_entity_name(self):
"""Return the entity name."""
return True

@property
def icon(self):
if "_ch" in self._name:
if "_ch" in self._unique_id:
return self._attr_icon_ch
return self._attr_icon_dhw

Expand All @@ -99,7 +111,7 @@ def supported_features(self):
@property
def hvac_mode(self):
"""Return current operation mode."""
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
return self._hvac_mode
return self._man_hvac_mode
Expand All @@ -113,7 +125,7 @@ def target_temperature_step(self):
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
return self._target_temperature
return self._man_target_temperature
Expand All @@ -122,7 +134,7 @@ def target_temperature(self):
@property
def current_temperature(self):
"""Return the current temperature."""
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
return self._temperature
return self._man_temperature
Expand All @@ -131,7 +143,7 @@ def current_temperature(self):
@property
def min_temp(self):
"""Return the minimum temperature."""
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
return 4 # Minimum temperature that can be set
return 35
Expand All @@ -140,7 +152,7 @@ def min_temp(self):
@property
def max_temp(self):
"""Return the maximum temperature."""
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
return 30
return 80
Expand All @@ -149,15 +161,15 @@ def max_temp(self):
@property
def hvac_action(self):
"""Return current HVAC mode."""
if "_ch" in self._name:
if "_ch" in self._unique_id:
return self._operation
return self._dhw_operation

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
mode = "1" if hvac_mode == HVACMode.HEAT else "0"
command = None
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
self._hvac_mode = hvac_mode
command = '{"atm":' + mode + "}"
Expand Down Expand Up @@ -189,7 +201,7 @@ async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
command = None
if ATTR_TEMPERATURE in kwargs:
if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
self._target_temperature = kwargs[ATTR_TEMPERATURE]
command = '{"trt":' + str(self._target_temperature) + "}"
Expand Down Expand Up @@ -234,7 +246,7 @@ async def async_update(self):
else:
self._mode_set = True

if "_ch" in self._name:
if "_ch" in self._unique_id:
if self._mode:
op_mode = data.get("atm", self._mode)
self._hvac_mode = HVACMode.HEAT if op_mode else HVACMode.OFF
Expand Down
10 changes: 10 additions & 0 deletions custom_components/airtub_udp/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,15 @@
}
}
}
},
"entity": {
"climate": {
"ch_control": {
"name": "Heating Control"
},
"dhw_control": {
"name": "Hot Water Control"
}
}
}
}
10 changes: 10 additions & 0 deletions custom_components/airtub_udp/translations/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,15 @@
}
}
}
},
"entity": {
"climate": {
"ch_control": {
"name": "采暖控制"
},
"dhw_control": {
"name": "热水控制"
}
}
}
}