petretiandrea / home-assistant-tapo-p100

A custom integration to control Tapo devices from home assistant.
MIT License
818 stars 102 forks source link

Tapo Bulb L530 set to cool white makes it unavailable #22

Closed maximilianneumann closed 3 years ago

maximilianneumann commented 3 years ago

Version of the custom_component

v1.0

Describe the bug

Tapo Bulb L530 set to cool white makes it unavailable. When the slider is set to the coolest setting (153), the bulb becomes unavailable. Sometimes it will be back after a few minutes or after a restart.

Debug log


2021-04-19 12:10:11 ERROR (MainThread) [custom_components.tapo] Unexpected exception from <bound method DataUpdateCoordinator.async_refresh of <custom_components.tapo.TapoUpdateCoordinator object at 0x7f8a6ba7f0>>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 104, in _handle_timer_finish
await task
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 161, in async_refresh
await self._async_refresh(log_failures=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 235, in _async_refresh
update_callback()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 295, in _handle_coordinator_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 310, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 334, in _async_write_ha_state
sstate = self.state
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 704, in state
return STATE_ON if self.is_on else STATE_OFF
File "/config/custom_components/tapo/light.py", line 47, in is_on
return self._tapo_coordinator.data.device_on
AttributeError: 'NoneType' object has no attribute 'device_on'
2021-04-19 12:10:30 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall light.turn_on (c:7f0fd406fc21bf4e5461af02bc809402): entity_id=['light.tapo_bulb_l530'], params=color_temp=153>
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/tapo/tapo_entity.py", line 31, in _execute_with_fallback
return await function()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 118, in set_color_temperature
return await self.set_device_info(LightParams(color_temperature=color_temperature))
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 76, in set_device_info
await self._set_device_info(device_params.as_dict(), terminal_uuid)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 106, in _set_device_info
self.__validate_response(decrypted_inner_response)
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 228, in __validate_response
raise TapoException.from_error_code(resp['error_code'])
plugp100.core.exceptions.TapoException.TapoException: Returned unknown error_code: -1008
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/core.py", line 1496, in catch_exceptions
await coro_or_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 322, in async_handle_light_on_service
await light.async_turn_on(**params)
File "/config/custom_components/tapo/light.py", line 94, in async_turn_on
await self._change_color_temp(color_temp)
File "/config/custom_components/tapo/light.py", line 115, in _change_color_temp
await self._execute_with_fallback(
File "/config/custom_components/tapo/tapo_entity.py", line 34, in _execute_with_fallback
return await self._execute_with_fallback(function, False)
File "/config/custom_components/tapo/tapo_entity.py", line 34, in _execute_with_fallback
return await self._execute_with_fallback(function, False)
File "/config/custom_components/tapo/tapo_entity.py", line 34, in _execute_with_fallback
return await self._execute_with_fallback(function, False)
[Previous line repeated 17 more times]
File "/config/custom_components/tapo/tapo_entity.py", line 33, in _execute_with_fallback
await self.coordinator.api.login()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 69, in login
await self._handshake()
File "/usr/local/lib/python3.8/site-packages/plugp100/api.py", line 146, in _handshake
self.tp_link_cipher = self.encryption.decode_handshake_key(resp_dict['result']['key'], self.key_pair)
File "/usr/local/lib/python3.8/site-packages/plugp100/core/encryption.py", line 40, in decode_handshake_key
raise ValueError("Decryption failed!")
ValueError: Decryption failed!
maximilianneumann commented 3 years ago

I found that it is a conversion error, between mired and kelvin. The bulb can go to 6500 kelvin. The closest value that worked for me was 6493 kelvin, anything above crashes the bulb.

petretiandrea commented 3 years ago

I need to understand if is a problem related to this plugin or the problem is inside the plugp100 that manage decryption and encryption.

You can try to use this snippet of code to see if the lamp turn on to 6500K or if the library report an error. First install the library using python pip: pip install plugp100==2.1.5. After that try this snippet:

import asyncio
from plugp100 import TapoApiClient, TapoDeviceState

async def main():
    # create generic tapo api
    client = TapoApiClient('lamp_ip', 'tapo_username', 'tapo_password')
    await client.login()
    await client.on()
    await client.set_color_temperature(6500)
    print(await sw.get_state())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()

Thanks for support :)

maximilianneumann commented 3 years ago

I have tried it, but I can't get a connection to that bulb. Also can't ping it. All other devices respond to pings, even tapo plugs. That is what I got:

Traceback (most recent call last):
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 494, in sock_connect
    return await fut
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 526, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.178.36', 80)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "test.py", line 7, in main
    await client.login()
  File "/home/maximilian/.local/lib/python3.8/site-packages/plugp100/api.py", line 69, in login
    await self._handshake()
  File "/home/maximilian/.local/lib/python3.8/site-packages/plugp100/api.py", line 138, in _handshake
    response = await self.http.async_make_post(self.url, json=request_body)
  File "/home/maximilian/.local/lib/python3.8/site-packages/plugp100/core/http_client.py", line 13, in async_make_post
    async with self.session.post(url, json=json) as response:
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/home/maximilian/.local/lib/python3.8/site-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.178.36:80 ssl:default [Connect call failed ('192.168.178.36', 80)]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f64cef1f5e0>
maximilianneumann commented 3 years ago

Now it worked, bulb gets set to that color and returns:

dedd12f214dc97c2992d6f8800f8667107e52fd9
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "test.py", line 10, in main
    print(await sw.get_state())
NameError: name 'sw' is not defined
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f740d0b25e0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f740c41d160>, 1377.160392955)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f740d0b2e50>

Edit: and I can see that it is set to exactly 6500k

petretiandrea commented 3 years ago

Now it worked, bulb gets set to that color and returns:

dedd12f214dc97c2992d6f8800f8667107e52fd9
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "test.py", line 10, in main
    print(await sw.get_state())
NameError: name 'sw' is not defined
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f740d0b25e0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f740c41d160>, 1377.160392955)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f740d0b2e50>

Edit: and I can see that it is set to exactly 6500k

Sorry in my snippet is use sw instead client, change to print(await client.get_state())

maximilianneumann commented 3 years ago
dedd12f214dc97c2992d6f8800f8667107e52fd9
TapoDeviceState(device_id='8023A49C5363B18E80E34A4F1ABCA91B1DB7BA17', nickname='Tapo Bulb L530', model='L530 Series', type='SMART.TAPOBULB', device_on=True, brightness=100, hue=None, saturation=None, color_temp=6500, overheated=False, signal_level=3, rssi=-42)
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f26473ed580>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f2646757160>, 2152.327599913)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f26473eddf0>
petretiandrea commented 3 years ago

I have checked the code: the mired and kelvin are correctly converted, but there is a problem related to approximation. 6500k are converted into 153.84 mired, because home assistant kelvin_to_mired is implemented as follows:

def color_temperature_kelvin_to_mired(kelvin_temperature):
    """Convert degrees kelvin to mired shift."""
    return 1000000 / kelvin_temperature

This means that GUI show the coolest option as 153 (due approximation), but the conversion from kelvin to mired, is implemented as follows:

def color_temperature_mired_to_kelvin(mired_temperature):
    """Convert absolute mired shift to degrees kelvin."""
    return 1000000 / mired_temperature

That return a value higher than 6500K for 153 as mired, this cause the crash of the lamp. Now I will check my clamp function that was meant to prevent this situation.

Anyway, I think that in your log there is some problem related to #23

maximilianneumann commented 3 years ago

Thanks for working on that :)

It might be related. But for #23 I have posted the complete log, where I only flip the switches until the error occurred.

petretiandrea commented 3 years ago

Try to update the integration from hacs, the fix should work :)

maximilianneumann commented 3 years ago

Yes it works!

Thank you :)

ps: do you have any idea for #23 ?