-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Daikin Climate - Better integration with Climate base component #16913
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
Changes from 1 commit
c97dae4
922af63
fe5bb82
4864833
e4f537c
5ed1eb1
8fb9925
5d92aea
6a192ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,15 @@ | |
| STATE_OFF: 'off', | ||
| } | ||
|
|
||
| DAIKIN_TO_HA_STATE = { | ||
| 'fan': STATE_FAN_ONLY, | ||
| 'dry': STATE_DRY, | ||
| 'cool': STATE_COOL, | ||
| 'hot': STATE_HEAT, | ||
| 'auto': STATE_AUTO, | ||
| 'off': STATE_OFF, | ||
| } | ||
|
|
||
| HA_ATTR_TO_DAIKIN = { | ||
| ATTR_OPERATION_MODE: 'mode', | ||
| ATTR_FAN_MODE: 'f_rate', | ||
|
|
@@ -76,7 +85,7 @@ def __init__(self, api): | |
| self._force_refresh = False | ||
| self._list = { | ||
| ATTR_OPERATION_MODE: list( | ||
| map(str.title, set(HA_STATE_TO_DAIKIN.values())) | ||
| map(str, set(DAIKIN_TO_HA_STATE.values())) | ||
| ), | ||
| ATTR_FAN_MODE: list( | ||
| map( | ||
|
|
@@ -136,11 +145,17 @@ def get(self, key): | |
| elif key == ATTR_OPERATION_MODE: | ||
| # Daikin can return also internal states auto-1 or auto-7 | ||
| # and we need to translate them as AUTO | ||
| value = re.sub( | ||
| tmp_value = re.sub( | ||
| '[^a-z]', | ||
| '', | ||
| self._api.device.represent(daikin_attr)[1] | ||
| ).title() | ||
| ) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line contains whitespace |
||
| daikin_op_mode = DAIKIN_TO_HA_STATE[tmp_value] | ||
| if daikin_op_mode is not None: | ||
| value = DAIKIN_TO_HA_STATE.get(daikin_op_mode) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can this work? We already have the value from the dict in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that I can make this part a little bit better, as soon as I can I will do that. The if statement is definetly too much. But the dictionary DAIKIN_TO_HA_STATE is necessary to map the operation_mode from the AC into the accepted one in HA climate component (there are some mismatch, like ‘heat’ vs ‘hot’). That’s way in the previous version the localization wasn’t working.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but you're using the same dictionary twice. That looks like a bug. We should only need to do one lookup.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m not an expert in Python (I work more with .NET tools), how can I use a key-value dictionary in “both direction”? (I mean, one time I’m using the key to get the value, and the next time I should use the value to get the key)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dictionaries in Python are "one way" only. Keys are unique, but values don't have to be unique. It's possible to iterate over a dictionary, check for a value and then save the key(s) that match the value. What is the goal with this part of the code? If you explain that we can try to figure out the best way.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ll try to explain: in the original component’s code, there was no mapping between the operation mode formthe daikin AC unit and the one for the base HA climate component. The list of available operation mode and the actual operation mode was just the ones available for the Daikin AC with a starting Uppercase. This was ok for most of the functionality, but what wasn’t working was:
I managed to make it eork using a dictionary to translate Daikin Operation Mode to HA Operation Mode (DAIKIN_TO_HA_STATE) and the other way around (HA_STATE_TO_DAIKIN). Since, as you point it out, the mapping is the same in the two direction, I can change the behavior removing the dictionary and using something like a Tuple (or at least that is what I would use in C#). Do you have any suggestion? Otherwhise tomorrow I’ll try to find sometime to fix this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dictionary is what we always use for translating modes between home assistant and device. You still didn't explain what you want to do with this part of the code. Do we want to end up with Daikin mode or home assistant mode, after the translation? If it's home assistant mode, we should only use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how I would expect us to do it: daikin_mode = re.sub(
'[^a-z]', '', self._api.device.represent(daikin_attr)[1])
ha_mode = DAIKIN_TO_HA_STATE.get(daikin_mode)
value = ha_mode |
||
| else: | ||
| value = tmp_value | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
|
|
||
| if value is None: | ||
| _LOGGER.error("Invalid value requested for key %s", key) | ||
|
|
@@ -262,4 +277,4 @@ def swing_list(self): | |
| def update(self): | ||
| """Retrieve latest state.""" | ||
| self._api.update(no_throttle=self._force_refresh) | ||
| self._force_refresh = False | ||
| self._force_refresh = False | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no newline at end of file |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the
strcopy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it a set doesn't seem necessary either. We know what the values are and they are unique. The dictionary is a constant so it won't change unless we change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this part I made just little modification to make it work properly, but the logics is the one from the original commit for the daikin component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're here, please clean it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to: