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

add new encryption method #165

Merged
merged 3 commits into from
May 27, 2024
Merged

Conversation

tomaszduda23
Copy link
Contributor

Add support for new version of encryption. It was mentioned tomikaa87/gree-remote#52

@RobHofmann
Copy link
Owner

Hi, i've just tested this. I'm getting a few errors (using the old encryption):

2024-05-26 13:26:46.294 ERROR (MainThread) [homeassistant.components.climate] Error while setting up gree platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/gree/climate.py", line 144, in async_setup_platform
    GreeClimate(hass, name, ip_addr, port, mac_addr, timeout, target_temp_step, temp_sensor_entity_id, lights_entity_id, xfan_entity_id, health_entity_id, powersave_entity_id, sleep_entity_id, eightdegheat_entity_id, air_entity_id, target_temp_entity_id, hvac_modes, fan_modes, swing_modes, preset_modes, auto_xfan, auto_light, encryption_version, encryption_key, uid)
  File "/config/custom_components/gree/climate.py", line 199, in __init__
    self._encryption_key = self.GetDeviceKey().encode("utf8")
                           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree/climate.py", line 302, in GetDeviceKey
    return self.FetchResult(cipher, self._ip_addr, self._port, self._timeout, jsonPayloadToSend)['key']
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree/climate.py", line 286, in FetchResult
    tag = receivedJson['tag']
          ~~~~~~~~~~~~^^^^^^^
KeyError: 'tag'
2024-05-26 13:26:46.379 ERROR (MainThread) [homeassistant.components.climate] Error while setting up gree platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/gree/climate.py", line 144, in async_setup_platform
    GreeClimate(hass, name, ip_addr, port, mac_addr, timeout, target_temp_step, temp_sensor_entity_id, lights_entity_id, xfan_entity_id, health_entity_id, powersave_entity_id, sleep_entity_id, eightdegheat_entity_id, air_entity_id, target_temp_entity_id, hvac_modes, fan_modes, swing_modes, preset_modes, auto_xfan, auto_light, encryption_version, encryption_key, uid)
  File "/config/custom_components/gree/climate.py", line 199, in __init__
    self._encryption_key = self.GetDeviceKey().encode("utf8")
                           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree/climate.py", line 302, in GetDeviceKey
    return self.FetchResult(cipher, self._ip_addr, self._port, self._timeout, jsonPayloadToSend)['key']
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree/climate.py", line 286, in FetchResult
    tag = receivedJson['tag']
          ~~~~~~~~~~~~^^^^^^^
KeyError: 'tag'
2024-05-26 13:26:46.451 ERROR (MainThread) [homeassistant.components.climate] Error while setting up gree platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/gree/climate.py", line 144, in async_setup_platform
    GreeClimate(hass, name, ip_addr, port, mac_addr, timeout, target_temp_step, temp_sensor_entity_id, lights_entity_id, xfan_entity_id, health_entity_id, powersave_entity_id, sleep_entity_id, eightdegheat_entity_id, air_entity_id, target_temp_entity_id, hvac_modes, fan_modes, swing_modes, preset_modes, auto_xfan, auto_light, encryption_version, encryption_key, uid)
  File "/config/custom_components/gree/climate.py", line 199, in __init__
    self._encryption_key = self.GetDeviceKey().encode("utf8")
                           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree/climate.py", line 302, in GetDeviceKey
    return self.FetchResult(cipher, self._ip_addr, self._port, self._timeout, jsonPayloadToSend)['key']
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/gree/climate.py", line 286, in FetchResult
    tag = receivedJson['tag']
          ~~~~~~~~~~~~^^^^^^^
KeyError: 'tag'

@tomaszduda23
Copy link
Contributor Author

Could you please check again? I have no version 1 unit to tests.

@RobHofmann
Copy link
Owner

Could you please check again? I have no version 1 unit to tests.

Seems to work now. Few code questions. Let me know :)

@tomaszduda23
Copy link
Contributor Author

Hmmm. I cannot see any questions.

@RobHofmann
Copy link
Owner

image
These 3 comments.

@tomaszduda23
Copy link
Contributor Author

You have to publish it to let others see.

@RobHofmann
Copy link
Owner

i think this should do the trick. can you now see it?

@tomaszduda23
Copy link
Contributor Author

I removed duplicated code. It should look better now.

@JensVanhooydonck
Copy link

This also works for v1.08 (Vaillant Firmware) 👍

@RobHofmann
Copy link
Owner

Works like a charm! Thanks :)

@RobHofmann RobHofmann merged commit ca39595 into RobHofmann:master May 27, 2024
@jodewee
Copy link

jodewee commented May 28, 2024

This also works for v1.08 (Vaillant Firmware) 👍

Hi @JensVanhooydonck , i have also the same brand, but can't get it to work even with this new release.
Did you also connect the ac to the app first? (i have mine in the gree & ewpe app)

  • platform: gree
    name: GREE_AC_Slaapkamer
    host: 192.168.2.108
    port: 7000
    target_temp_step: 1
    mac: '50:2c:c6:6c:d3:63 '
    encryption_version: 2

@JensVanhooydonck
Copy link

JensVanhooydonck commented May 28, 2024

This also works for v1.08 (Vaillant Firmware) 👍

Hi @JensVanhooydonck , i have also the same brand, but can't get it to work even with this new release. Did you also connect the ac to the app first? (i have mine in the gree & ewpe app)

  • platform: gree
    name: GREE_AC_Slaapkamer
    host: 192.168.2.108
    port: 7000
    target_temp_step: 1
    mac: '50:2c:c6:6c:d3:63 '
    encryption_version: 2

I've added them to the app, and extracted the encryption keys from the database (i'm on a macbook m1 => Opened the Sql-lite database to get the keys)

  name: Airco Office
  host: 192.168.0.147
  port: 7000
  mac: "502cc66cac26"
  target_temp_step: 1
  encryption_key: jRyGnTBiQxF3u8j3
  encryption_version: 2
  uid: 0

@jodewee
Copy link

jodewee commented May 28, 2024

Hi @JensVanhooydonck
many, many thanks man, after 2years of struggeling:
it also works without providing the encryption key.

  • platform: gree
    name: GREE_AC_Slaapkamer
    host: 192.168.2.108
    port: 7000
    target_temp_step: 1
    mac: "502cc66cd363"
    encryption_version: 2
    uid: 0

image

@toughvj
Copy link
Contributor

toughvj commented May 28, 2024

@tomaszduda23 powieliliście ten sam błąd, który był w oryginalnym kodzie.

@jodewee
Copy link

jodewee commented May 29, 2024

I can confirm it is working flawlessly with:
Bulex vivair multisplit units:

  • 20-080MC4NO outdoor unit
  • 20-025 NWI (2,5 kW) indoor unit
  • 20-035 NWI (3,5 kW) indoor unit

@RobHofmann ; maybe it is possible to add this to the confirmed working units? (they are btw exact the same units as the saunier duval & vaillaint vivair series)

Configured it via the ewpe smart app. (also working in the gree app)

Only configuration needed in ha:

  • platform: gree
    name: ACNAMe
    host: xxx.xxx.xxx.xxx
    port: 7000
    target_temp_step: 1
    mac: "xxxxxxxxxx"
    encryption_version: 2
    uid: 0

all basic functions are tested & working correctly
image

@toughvj
Copy link
Contributor

toughvj commented May 29, 2024

In my opinion, there is a bug in the code from the very beginning that should be removed before any changes are made in the future. Retrieving a device key, unless it is provided in the configuration, should not occur in the class constructor. If for some reason a connection to the device is not established during the creation of the object, HA will throw an error, the device will not be added to the registry and it becomes unusable until the HA is restarted, but even then there is no guarantee that the key will be downloaded and we have an endless loop.

in my opinion, retrieving device key should be placed in async_added_to_hass as in #163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants