Răsfoiți Sursa

fix (valve): provide a default for switch

It seems pop throws an exception if the value is missing unless a default
is supplied.

This means we do not need the added exception for missing valve, but we
do need to provide a default of None for switch which we want to be
optional.
Jason Rumney 1 zi în urmă
părinte
comite
6ff9cee1d9
1 a modificat fișierele cu 1 adăugiri și 3 ștergeri
  1. 1 3
      custom_components/tuya_local/valve.py

+ 1 - 3
custom_components/tuya_local/valve.py

@@ -41,10 +41,8 @@ class TuyaLocalValve(TuyaLocalEntity, ValveEntity):
         super().__init__()
         dps_map = self._init_begin(device, config)
         self._valve_dp = dps_map.pop("valve")
-        self._switch_dp = dps_map.pop("switch")
+        self._switch_dp = dps_map.pop("switch", None)
         self._init_end(dps_map)
-        if self._valve_dp is None:
-            raise AttributeError(f"{config.config_id} is missing valve dp")
 
         if not self._valve_dp.readonly or self._switch_dp:
             self._attr_supported_features |= ValveEntityFeature.OPEN