The if is to determine current attribute value before changing. Then, if false (not set), it sets commsError to true. So, it is correct.
Error process design.
The first and second command failures are retried automatically.
On the third, the app is asked to perform a fix - polling each child device and (if found) updating the IP address. Then the command is tried again. The fourth try sets the comms error as well as changing polling interval to 30 minutes.
Future failures are not retried (until the comms error is set to true).
The comms error is kept true until there is a successful entry. At that time, commsError is set false and the poll interval is reset to the user selection. And the cycle starts again.
Cloud bind: If the device is binded to the Kasa Cloud, then
a. the Kasa Cloud will maintain the state (Kasa request a periodic update over the WAN.
b. you can control the device with the Kasa Phone App when not at home OR away.
If not bound:
a. the Kasa Cloud will not maintain the state
b. you will only be able to control through the Kasa Phone App when at home (and your phone is on the local LAN).
OK. The message indicates the driver is not installed. One possible reason for the HPM error earlier is the driver Kasa Plug Switch is missing from your Drivers folder.
In hpm, try a repair and see if that restores the missing driver.
If not, in hpm, modify the package Kasa and add the missing driver (All Plug-Switches).
Excuse me while I take this opportunity to thank you for your work on this integration. I've purchased a few different Kasa products and along with your app they are working perfectly.
Update Note: After updating the APP and DRIVERS, do one of the following to assure proper operation (especially of the EM Funtion). Either of these actions will configure all devices and the app to new data and updated scheduling.
Open the App and simply exit OR,
Open any ONE device's edit page and select the command "configure"