Merge branch 'stability_fixes' of github.com:rospogrigio/localtuya into stability_fixes
This commit is contained in:
@@ -81,7 +81,6 @@ async def async_setup_entry(
|
|||||||
]
|
]
|
||||||
|
|
||||||
if entities_to_setup:
|
if entities_to_setup:
|
||||||
|
|
||||||
tuyainterface = hass.data[DOMAIN][TUYA_DEVICES][dev_id]
|
tuyainterface = hass.data[DOMAIN][TUYA_DEVICES][dev_id]
|
||||||
|
|
||||||
dps_config_fields = list(get_dps_for_platform(flow_schema))
|
dps_config_fields = list(get_dps_for_platform(flow_schema))
|
||||||
@@ -196,7 +195,9 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
|
|||||||
)
|
)
|
||||||
self._interface.add_dps_to_request(self.dps_to_request)
|
self._interface.add_dps_to_request(self.dps_to_request)
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
self.warning(f"Connect to {self._dev_config_entry[CONF_HOST]} failed attempting to connect")
|
self.warning(
|
||||||
|
f"Connect to {self._dev_config_entry[CONF_HOST]} failed attempting to connect"
|
||||||
|
)
|
||||||
if self._interface is not None:
|
if self._interface is not None:
|
||||||
await self._interface.close()
|
await self._interface.close()
|
||||||
self._interface = None
|
self._interface = None
|
||||||
@@ -231,14 +232,10 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
|
|||||||
self._interface.start_heartbeat()
|
self._interface.start_heartbeat()
|
||||||
self.status_updated(status)
|
self.status_updated(status)
|
||||||
else:
|
else:
|
||||||
self.error(
|
self.error(f"Initial state update failed, giving up: %r", ex)
|
||||||
f"Initial state update failed, giving up: %r", ex
|
|
||||||
)
|
|
||||||
# return
|
# return
|
||||||
except (UnicodeDecodeError, json.decoder.JSONDecodeError) as ex:
|
except (UnicodeDecodeError, json.decoder.JSONDecodeError) as ex:
|
||||||
self.exception(
|
self.exception(f"Initial state update failed, trying key update")
|
||||||
f"Initial state update failed, trying key update"
|
|
||||||
)
|
|
||||||
await self.update_local_key()
|
await self.update_local_key()
|
||||||
|
|
||||||
if self._interface is not None:
|
if self._interface is not None:
|
||||||
@@ -266,12 +263,12 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
CONF_SCAN_INTERVAL in self._dev_config_entry
|
CONF_SCAN_INTERVAL in self._dev_config_entry
|
||||||
and self._dev_config_entry[CONF_SCAN_INTERVAL] > 0
|
and int(self._dev_config_entry[CONF_SCAN_INTERVAL]) > 0
|
||||||
):
|
):
|
||||||
self._unsub_interval = async_track_time_interval(
|
self._unsub_interval = async_track_time_interval(
|
||||||
self._hass,
|
self._hass,
|
||||||
self._async_refresh,
|
self._async_refresh,
|
||||||
timedelta(seconds=self._dev_config_entry[CONF_SCAN_INTERVAL]),
|
timedelta(seconds=int(self._dev_config_entry[CONF_SCAN_INTERVAL])),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.info(f"Successfully connected to {self._dev_config_entry[CONF_HOST]}")
|
self.info(f"Successfully connected to {self._dev_config_entry[CONF_HOST]}")
|
||||||
|
@@ -140,7 +140,7 @@ def options_schema(entities):
|
|||||||
["3.1", "3.2", "3.3", "3.4"]
|
["3.1", "3.2", "3.3", "3.4"]
|
||||||
),
|
),
|
||||||
vol.Required(CONF_ENABLE_DEBUG, default=False): bool,
|
vol.Required(CONF_ENABLE_DEBUG, default=False): bool,
|
||||||
vol.Optional(CONF_SCAN_INTERVAL): cv.string,
|
vol.Optional(CONF_SCAN_INTERVAL): int,
|
||||||
vol.Optional(CONF_MANUAL_DPS): cv.string,
|
vol.Optional(CONF_MANUAL_DPS): cv.string,
|
||||||
vol.Optional(CONF_RESET_DPIDS): cv.string,
|
vol.Optional(CONF_RESET_DPIDS): cv.string,
|
||||||
vol.Required(
|
vol.Required(
|
||||||
@@ -269,7 +269,6 @@ async def validate_input(hass: core.HomeAssistant, data):
|
|||||||
# if manual DPs are set, merge these.
|
# if manual DPs are set, merge these.
|
||||||
_LOGGER.debug("Detected DPS: %s", detected_dps)
|
_LOGGER.debug("Detected DPS: %s", detected_dps)
|
||||||
if CONF_MANUAL_DPS in data:
|
if CONF_MANUAL_DPS in data:
|
||||||
|
|
||||||
manual_dps_list = [dps.strip() for dps in data[CONF_MANUAL_DPS].split(",")]
|
manual_dps_list = [dps.strip() for dps in data[CONF_MANUAL_DPS].split(",")]
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Manual DPS Setting: %s (%s)", data[CONF_MANUAL_DPS], manual_dps_list
|
"Manual DPS Setting: %s (%s)", data[CONF_MANUAL_DPS], manual_dps_list
|
||||||
@@ -599,12 +598,15 @@ class LocalTuyaOptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
if dev_id in cloud_devs:
|
if dev_id in cloud_devs:
|
||||||
cloud_local_key = cloud_devs[dev_id].get(CONF_LOCAL_KEY)
|
cloud_local_key = cloud_devs[dev_id].get(CONF_LOCAL_KEY)
|
||||||
if defaults[CONF_LOCAL_KEY] != cloud_local_key:
|
if defaults[CONF_LOCAL_KEY] != cloud_local_key:
|
||||||
_LOGGER.info("New local_key detected: new %s vs old %s",
|
_LOGGER.info(
|
||||||
|
"New local_key detected: new %s vs old %s",
|
||||||
cloud_local_key,
|
cloud_local_key,
|
||||||
defaults[CONF_LOCAL_KEY]
|
defaults[CONF_LOCAL_KEY],
|
||||||
)
|
)
|
||||||
defaults[CONF_LOCAL_KEY] = cloud_devs[dev_id].get(CONF_LOCAL_KEY)
|
defaults[CONF_LOCAL_KEY] = cloud_devs[dev_id].get(CONF_LOCAL_KEY)
|
||||||
placeholders = {"for_device": f" for device `{dev_id}`.\nNOTE: a new local_key has been retrieved using cloud API"}
|
placeholders = {
|
||||||
|
"for_device": f" for device `{dev_id}`.\nNOTE: a new local_key has been retrieved using cloud API"
|
||||||
|
}
|
||||||
schema = schema_defaults(options_schema(self.entities), **defaults)
|
schema = schema_defaults(options_schema(self.entities), **defaults)
|
||||||
else:
|
else:
|
||||||
defaults[CONF_PROTOCOL_VERSION] = "3.3"
|
defaults[CONF_PROTOCOL_VERSION] = "3.3"
|
||||||
|
@@ -449,7 +449,9 @@ class MessageDispatcher(ContextualLogger):
|
|||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
|
await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
self.warning("Command %d timed out waiting for sequence number %d", cmd, seqno)
|
self.warning(
|
||||||
|
"Command %d timed out waiting for sequence number %d", cmd, seqno
|
||||||
|
)
|
||||||
del self.listeners[seqno]
|
del self.listeners[seqno]
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user