Skip to content

Commit

Permalink
Fix #224: Error noiseSensorStarted аfter updating to the version 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Oct 21, 2022
1 parent cd96a0d commit 8ca22fa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions custom_components/tapo_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ async def async_update_data():
LOGGER.error(e)
hass.data[DOMAIN][entry.entry_id]["camData"] = camData

LOGGER.debug("Updating entities...")
for entity in hass.data[DOMAIN][entry.entry_id]["entities"]:
if entity._enabled:
entity.updateTapo(camData)
Expand Down Expand Up @@ -284,6 +285,7 @@ async def async_update_data():
"events": False,
"eventsListener": False,
"entities": [],
"noiseSensorStarted": False,
"name": camData["basic_info"]["device_alias"],
}

Expand Down
2 changes: 0 additions & 2 deletions custom_components/tapo_control/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def __init__(self, entry: dict, hass: HomeAssistant, config_entry):

self._attr_state = "unavailable"

self._hass.data[DOMAIN][config_entry.entry_id]["noiseSensorStarted"] = False

LOGGER.debug("TapoNoiseBinarySensor - init - end")

async def startNoiseDetection(self):
Expand Down
17 changes: 17 additions & 0 deletions custom_components/tapo_control/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ def updateTapo(self, camData):
self._attr_state = self._attr_current_option

async def async_select_option(self, option: str) -> None:
LOGGER.debug(
"setAlarm("
+ str(option != "off")
+ ", "
+ str(option == "off" or option in ["both", "sound"])
+ ", "
+ str(option == "off" or option in ["both", "light"])
+ ")"
)
await self.hass.async_add_executor_job(
self._controller.setAlarm,
option != "off",
Expand Down Expand Up @@ -161,13 +170,21 @@ def updateTapo(self, camData):
else:
self._attr_current_option = camData["motion_detection_sensitivity"]
self._attr_state = self._attr_current_option
LOGGER.debug("Updating TapoMotionDetectionSelect to: " + self._attr_state)

async def async_select_option(self, option: str) -> None:
await self.hass.async_add_executor_job(
self._controller.setMotionDetection,
option != "off",
option if option != "off" else False,
)
LOGGER.debug(
"setMotionDetection("
+ str(option != "off")
+ ", "
+ (str(option) if option != "off" else str(False))
+ ")"
)
await self._coordinator.async_request_refresh()


Expand Down
3 changes: 3 additions & 0 deletions custom_components/tapo_control/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,21 @@ async def async_turn_on(self) -> None:
await self._hass.async_add_executor_job(
self._controller.setPrivacyMode, True,
)
LOGGER.debug("setPrivacyMode(" + str(True) + ")")

async def async_turn_off(self) -> None:
await self._hass.async_add_executor_job(
self._controller.setPrivacyMode, False,
)
LOGGER.debug("setPrivacyMode(" + str(False) + ")")

def updateTapo(self, camData):
if not camData:
self._attr_state = "unavailable"
else:
self._attr_is_on = camData["privacy_mode"] == "on"
self._attr_state = "on" if self._attr_is_on else "off"
LOGGER.debug("Updating TapoPrivacySwitch to: " + self._attr_state)

@property
def icon(self) -> str:
Expand Down

0 comments on commit 8ca22fa

Please sign in to comment.