Skip to content

Commit 0c866c9

Browse files
committed
Add #1269: Preset Patrol mode switch entity
1 parent cf1d03f commit 0c866c9

5 files changed

Lines changed: 72 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Doorbells, Cameras (for each lens, if supported):
7070
- Binary sensor for motion after the motion is detected for the first time and a binary sensor for doorbell press
7171
- Light entity, if the camera supports a floodlight switch
7272
- Buttons for Calibrate, Format, Manual Alarm start & stop, Moving the camera, Reboot and syncing time
73-
- Switch entities for Auto track, Automatic Reboot, Flip setting, LED Indicator, Lens Distortion Correction, (Rich) Notifications, Recording, Microphone Mute, Microphone Noise Cancelling, Automatically Upgrade Firmware, HDR mode, Alarm Trigger Event types, Privacy Zones, Diagnose Mode, Smart Track specific switches, Smart Dual Track specific switches, Audio Recording and Privacy mode
73+
- Switch entities for Auto track, Automatic Reboot, Flip setting, LED Indicator, Lens Distortion Correction, (Rich) Notifications, Recording, Microphone Mute, Microphone Noise Cancelling, Automatically Upgrade Firmware, HDR mode, Alarm Trigger Event types, Privacy Zones, Diagnose Mode, Smart Track specific switches, Smart Dual Track specific switches, Preset Patrol Mode, Audio Recording and Privacy mode
7474
- Select entities for Automatic Alarm, Automatic Reboot Time, Light Frequency, Motion Detection, Night Vision, Spotlight Intensity, Alarm Type, Quick Response, Smart Dual Track Method and Move to Preset
7575
- Number entity for Movement Angle, Speaker Volume, Microphone Volume, Spotlight Intensity, Siren Volume, Siren Duration and Motion Detection Digital Sensitivity
7676
- Media Source for browsing and playing recordings stored on camera

custom_components/tapo_control/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
TPLINK_DOMAIN = "tplink"
1010

1111
CONTROL_PORT = "control_port"
12-
PYTAPO_REQUIRED_VERSION = "3.4.16"
12+
PYTAPO_REQUIRED_VERSION = "3.4.17"
1313
DOMAIN = "tapo_control"
1414
DOMAIN_CONFIG = DOMAIN + "_config"
1515
BRAND = "TP-Link"

custom_components/tapo_control/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"codeowners": [
77
"@JurajNyiri"
88
],
9-
"version": "7.1.22",
9+
"version": "7.1.23",
1010
"requirements": [
11-
"pytapo==3.4.16",
11+
"pytapo==3.4.17",
1212
"python-kasa[speedups]==0.10.2"
1313
],
1414
"dependencies": [
@@ -39,4 +39,4 @@
3939
"loggers": [
4040
"custom_components.tapo_control"
4141
]
42-
}
42+
}

custom_components/tapo_control/switch.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ async def setupEntities(entry):
176176
LOGGER.debug("Adding tapoAutoTrackSwitch...")
177177
switches.append(tapoAutoTrackSwitch)
178178

179+
tapoPatrolModeSwitch = await check_and_create(
180+
entry, hass, TapoPatrolModeSwitch, "getCruise", config_entry
181+
)
182+
if tapoPatrolModeSwitch:
183+
LOGGER.debug("Adding tapoPatrolModeSwitch...")
184+
switches.append(tapoPatrolModeSwitch)
185+
179186
tapoNotificationsSwitch = await check_and_create(
180187
entry,
181188
hass,
@@ -1285,3 +1292,55 @@ def updateTapo(self, camData):
12851292
else:
12861293
self._attr_is_on = camData["auto_track"] == "on"
12871294
self._attr_state = "on" if self._attr_is_on else "off"
1295+
1296+
1297+
class TapoPatrolModeSwitch(TapoSwitchEntity):
1298+
def __init__(self, entry: dict, hass: HomeAssistant, config_entry):
1299+
TapoSwitchEntity.__init__(
1300+
self,
1301+
"Preset Patrol Mode",
1302+
entry,
1303+
hass,
1304+
config_entry,
1305+
"mdi:map-marker-path",
1306+
)
1307+
1308+
async def async_update(self) -> None:
1309+
await self._coordinator.async_request_refresh()
1310+
1311+
async def async_turn_on(self) -> None:
1312+
result = await self._hass.async_add_executor_job(
1313+
self._controller.setPatrolStatus,
1314+
True,
1315+
)
1316+
if "error_code" not in result or result["error_code"] == 0:
1317+
self._attr_is_on = True
1318+
self._attr_state = "on"
1319+
self.async_write_ha_state()
1320+
await self._coordinator.async_request_refresh()
1321+
1322+
async def async_turn_off(self) -> None:
1323+
result = await self._hass.async_add_executor_job(
1324+
self._controller.setPatrolStatus,
1325+
False,
1326+
)
1327+
if "error_code" not in result or result["error_code"] == 0:
1328+
self._attr_is_on = False
1329+
self._attr_state = "off"
1330+
self.async_write_ha_state()
1331+
await self._coordinator.async_request_refresh()
1332+
1333+
def updateTapo(self, camData):
1334+
if (
1335+
not camData
1336+
or camData.get("privacy_mode") == "on"
1337+
or camData.get("patrol_status") is None
1338+
):
1339+
self._attr_state = STATE_UNAVAILABLE
1340+
else:
1341+
self._attr_is_on = camData["patrol_status"] != "idle"
1342+
self._attr_state = "on" if self._attr_is_on else "off"
1343+
1344+
@property
1345+
def entity_category(self):
1346+
return None

custom_components/tapo_control/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,12 @@ async def getCamData(hass, controller, chInfo=None):
16941694
else:
16951695
camData["presets"] = {}
16961696

1697+
try:
1698+
patrolStatus = data["getPatrolAction"][0]["patrol"]["patrol"]["action"]
1699+
except Exception:
1700+
patrolStatus = None
1701+
camData["patrol_status"] = patrolStatus
1702+
16971703
try:
16981704
firmwareUpdateStatus = data["getFirmwareUpdateStatus"][0]["cloud_config"]
16991705
except Exception:
@@ -2194,6 +2200,8 @@ def pytapoFunctionMap(pytapoFunctionName):
21942200
return ["getTargetTrackConfig"]
21952201
elif pytapoFunctionName == "getPresets":
21962202
return ["getPresetConfig"]
2203+
elif pytapoFunctionName == "getCruise":
2204+
return ["getPatrolAction"]
21972205
elif pytapoFunctionName == "getLightFrequencyMode":
21982206
return ["getLightFrequencyInfo", "getLightFrequencyCapability"]
21992207
elif pytapoFunctionName == "getChildDevices":

0 commit comments

Comments
 (0)