Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
titlepyTuyaBulb/src/acsiotImpl/Tuya/bulbImplTuyaBulbImpl.py
linenumberstrue
# Client stubs and definitions, such as structs, enums, etc.
import acsiot
# Skeleton infrastructure for server implementation
import acsiot__POA
   
# Base component implementation
from Acspy.Servants.ACSComponent import ACSComponent
# Services provided by the container to the component
from Acspy.Servants.ContainerServices import ContainerServices
# Basic component lifecycle (initialize, execute, cleanUp and aboutToAbort methods)
from Acspy.Servants.ComponentLifecycle import ComponentLifecycle

import tinytuya
tinytuya.set_debug(True)


class TuyaBulbImpl(acsiot__POA.TuyaBulb, ACSComponent, ContainerServices, ComponentLifecycle):
    def __init__(self):
        ACSComponent.__init__(self)
        ContainerServices.__init__(self)
        self._logger = self.getLogger()
        
    def turnOn(self, api_region, api_key, api_secret, device_id):
        # raise NotImplementedError("This function should do something")
        client = tinytuya.Cloud(
            apiRegion=api_region,
            apiKey=api_key,
            apiSecret=api_secret
        )

        commands = {
            'commands': [{
                'code': 'switch_led',
                'value': True
            }]
        }
        print("Sending command...")
        result = client.sendcommand(device_id, commands)
        print("Results\n:", result)

    def turnOff(self, api_region, api_key, api_secret, device_id):
        # raise NotImplementedError("This function should do something")
        client = tinytuya.Cloud(
            apiRegion=api_region,
            apiKey=api_key,
            apiSecret=api_secret
        )

        commands = {
            'commands': [{
                'code': 'switch_led',
                'value': False
            }]
        }
        print("Sending command...")
        result = client.sendcommand(device_id, commands)
        print("Results\n:", result)

...