Skip to content

Commit

Permalink
Merge pull request #466 from uzlonewolf/misc-20240222
Browse files Browse the repository at this point in the history
Misc 2024-02-22
  • Loading branch information
jasonacox authored Feb 24, 2024
2 parents 879d896 + 477d965 commit a287564
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TinyTuya has a built-in setup Wizard that uses the Tuya IoT Cloud Platform to ge
1. Pick the correct Data Center "Region" for your location (check [HERE](https://developer.tuya.com/en/docs/iot/oem-app-data-center-distributed?id=Kafi0ku9l07qb#title-3-Western%20America%20Data%20Center) to find your Region). This will be used by TinyTuya Wizard ([screenshot](https://user-images.githubusercontent.com/836718/138598647-c9657e49-1a89-4ed6-8105-ceee95d9513f.png)).
2. Skip the configuration wizard but remember the Authorization Key: *API ID* and *Secret* for below ([screenshot](https://user-images.githubusercontent.com/836718/138598788-f74d2fe8-57fa-439c-8003-18735a44e7e5.png)).
* Click on "Cloud" icon -> Select your project -> **Devices** -> **Link Tuya App Account** ([see screenshot](https://user-images.githubusercontent.com/836718/155827671-44d5fce4-0119-4d0e-a224-ef3715fafc24.png))
* Click **Add App Account** ([screenshot](https://user-images.githubusercontent.com/836718/273364035-0fd133b7-4e9e-4a6d-900e-efe63d69f1a0.png)) and it will pop-up a "Link Tuya App Account" dialog, chose "Automatic" and "Read Only Status" (it will still alow commands). Click OK and it will display a QR code. Scan the QR code with the *Smart Life app* on your Phone (see step 1 above) by going to the "Me" tab in the *Smart Life app* and clicking on the QR code button `[..]` in the upper right hand corner of the app. When you scan the QR code, it will link all of the devices registered in your *Smart Life app* into your Tuya IoT project.
* Click **Add App Account** ([screenshot](https://user-images.githubusercontent.com/836718/273364035-0fd133b7-4e9e-4a6d-900e-efe63d69f1a0.png)) and it will pop-up a "Link Tuya App Account" dialog, chose "Automatic" and "Read Only Status" (it will still alow commands). Click OK and it will display a QR code. Scan the QR code with the *Smart Life app* on your Phone (see step 1 above) by going to the "Me" tab in the *Smart Life app* and clicking on the QR code button `[..]` in the upper right hand corner of the app. When you scan the QR code, it will link all of the devices registered in your *Smart Life app* into your Tuya IoT project. If the QR code will not scan then make sure to disable any browser theming plug-ins (such as Dark Reader) and try again.
* **NO DEVICES?** If no devices show up after scanning the QR code, you will need to select a different data center and edit your project (or create a new one) until you see your paired devices from the *Smart Life App* show up. ([screenshot](https://user-images.githubusercontent.com/35581194/148679597-391adecb-a271-453b-90c0-c64cdfad42e4.png)). The data center may not be the most logical. As an example, some in the UK have reported needing to select "Central Europe" instead of "Western Europe".
* **SERVICE API:** Under "Service API" ensure these APIs are listed: `IoT Core` and `Authorization`. To be sure, click subscribe again on every service. Very important: **disable popup blockers** otherwise subscribing won't work without providing any indication of a failure. Make sure you authorize your Project to use those APIs:
- Click "Service API" tab
Expand Down
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# RELEASE NOTES

## v1.13.2 - Contrib Updates

* Makes some tweaks to the recently-added Contrib/PresenceDetectorDevice by @mrioan and Deprecates Contrib/__init__.py by @uzlonewolf in https://github.com/jasonacox/tinytuya/pull/466
* And adds a note about QR code scanning with Dark Reader to the README. #463

## v1.13.1 - Cryptography Version

* PyPI 1.13.1
Expand Down
36 changes: 36 additions & 0 deletions examples/Contrib/PresenceDetectorDevice-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from tinytuya.Contrib import PresenceDetectorDevice
#from tinytuya import core
import time
import logging
import requests

log = logging.getLogger(__name__)
device_id = 'XXXX'
device_ip = 'YYYY'
local_key = 'ZZZZ'
iftt_url = "https://maker.ifttt.com/trigger/{webhook_name_here}/json/with/key/{key_here}"

def main():
setup()
run()

def setup():
global device
device = PresenceDetectorDevice.PresenceDetectorDevice(device_id, address=device_ip, local_key=local_key, version=3.3)

def run():
log.info(" >>>> Begin Monitor Loop <<<< ")
while(True):
presence = device.get_presence_state()
if (presence == 'presence'):
log.info('ALERT! Presence detected!')
presence_detected_steps()
else:
log.debug('no presence, sleep...')
time.sleep(20)

def presence_detected_steps():
requests.post(iftt_url, json={})

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions tinytuya/Contrib/PresenceDetectorDevice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tinytuya.core import Device
from ..core import Device
import time
import json

Expand Down Expand Up @@ -130,4 +130,4 @@ def get_target_distance(self):
status = self.status()
if "Error" in status:
return satus
return status[self.DPS_KEY][self.TARGET_DISTANCE_KEY]
return status[self.DPS_KEY][self.TARGET_DISTANCE_KEY]
43 changes: 11 additions & 32 deletions tinytuya/Contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,25 @@ In addition to the built-in `OutletDevice`, `BulbDevice` and `CoverDevice` devic

```python
from tinytuya.Contrib import PresenceDetectorDevice
from tinytuya import core
import time
import logging
import requests

log = logging.getLogger(__name__)
device_id = 'XXXX'
device_ip = 'YYYY'
local_key = 'ZZZZ'
iftt_url = "https://maker.ifttt.com/trigger/{webhook_name_here}/json/with/key/{key_here}"

def main():
setup()
run()

def setup():
global device
device = PresenceDetectorDevice(device_id, address=device_ip, local_key=local_key)
device.set_version(3.3)

def run():
log.info(" >>>> Begin Monitor Loop <<<< ")
while(True):
presence = device.get_presence_state()
if (presence == 'presence'):
log.info('ALERT! Presence detected!')
presence_detected_steps()
else:
log.debug('no presence, sleep...')
time.sleep(20)

def presence_detected_steps():
requests.post(iftt_url, json={})

if __name__ == "__main__":
main()

device = PresenceDetectorDevice.PresenceDetectorDevice(device_id, address=device_ip, local_key=local_key)

print(" >>>> Begin Monitor Loop <<<< ")
while(True):
presence = device.get_presence_state()
if (presence == 'presence'):
print('Presence detected!')
else:
print('no presence, sleep...')
time.sleep(20)
```

## Submit Your Device

* We welcome new device modules!
* Follow the template example in [ThermostatDevice.py](ThermostatDevice.py) to add your device.
* Add your module to the [__init__.py](__init__.py) file.
8 changes: 6 additions & 2 deletions tinytuya/Contrib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Note: This file has been deprecated, please do not add new modules to it.
# Instead, import new modules with `from tinytuya.Contrib import YourNewModule`
# and call with `YourNewModule.YourNewModule(...)`
#

from .ThermostatDevice import ThermostatDevice
from .IRRemoteControlDevice import IRRemoteControlDevice
Expand All @@ -6,6 +11,5 @@
from .ClimateDevice import ClimateDevice
from .AtorchTemperatureControllerDevice import AtorchTemperatureControllerDevice
from .InverterHeatPumpDevice import InverterHeatPumpDevice, TemperatureUnit, InverterHeatPumpMode, InverterHeatPumpFault
from .PresenceDetectorDevice import PresenceDetectorDevice

DeviceTypes = ["ThermostatDevice", "IRRemoteControlDevice", "SocketDevice", "DoorbellDevice", "ClimateDevice", "AtorchTemperatureControllerDevice", "InverterHeatPumpDevice", "PresenceDetectorDevice"]
DeviceTypes = ["ThermostatDevice", "IRRemoteControlDevice", "SocketDevice", "DoorbellDevice", "ClimateDevice", "AtorchTemperatureControllerDevice", "InverterHeatPumpDevice"]
2 changes: 1 addition & 1 deletion tinytuya/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
# Colorama terminal color capability for all platforms
init()

version_tuple = (1, 13, 1)
version_tuple = (1, 13, 2)
version = __version__ = "%d.%d.%d" % version_tuple
__author__ = "jasonacox"

Expand Down

0 comments on commit a287564

Please sign in to comment.