All Projects → tuya → tuya-connector

tuya / tuya-connector

Licence: Apache-2.0 License
tuya-connector helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilities. You can put all the focus on business logic without taking care of server-side programming nor relational databases.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to tuya-connector

Webapiclient
An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously.
Stars: ✭ 1,618 (+5678.57%)
Mutual labels:  restful, retrofit, openapi
tuya-home-assistant
Home Assistant integration for controlling Powered by Tuya (PBT) devices using Tuya Open API, maintained by the Home Assistant Community and Tuya Developer Team.
Stars: ✭ 684 (+2342.86%)
Mutual labels:  tuya-smart, tuya
StatefulLiveData
StatefulLiveData is a lean, yet powerful tool that harnesses the capabilities of LiveData and enhances them, enabling the observer to distinguish between different states the data can be in, such as Success, Loading and Error.
Stars: ✭ 18 (-35.71%)
Mutual labels:  retrofit, retrofit2
tuyasmart ios sdk
No description or website provided.
Stars: ✭ 22 (-21.43%)
Mutual labels:  tuya-smart, tuya
Php Crud Api
Single file PHP script that adds a REST API to a SQL database
Stars: ✭ 2,904 (+10271.43%)
Mutual labels:  restful, openapi
tinyspec
Simple syntax for describing REST APIs
Stars: ✭ 95 (+239.29%)
Mutual labels:  restful, openapi
rxjava2 retrofit2
rxjava2+retrofit2 网络封装
Stars: ✭ 19 (-32.14%)
Mutual labels:  retrofit, retrofit2
Swagger meqa
Auto generate and run tests using swagger/OpenAPI spec, no coding needed
Stars: ✭ 151 (+439.29%)
Mutual labels:  restful, openapi
java-crud-api
No description or website provided.
Stars: ✭ 24 (-14.29%)
Mutual labels:  restful, openapi
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-10.71%)
Mutual labels:  retrofit, retrofit2
RetrofitHelper
💪 RetrofitHelper是一个支持配置多个BaseUrl,支持动态改变BaseUrl,动态配置超时时长的Retrofit帮助类
Stars: ✭ 15 (-46.43%)
Mutual labels:  retrofit, retrofit2
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+9989.29%)
Mutual labels:  restful, openapi
Flama
🔥 Fire up your API with this flamethrower
Stars: ✭ 161 (+475%)
Mutual labels:  restful, openapi
restio
HTTP Client for Dart inspired by OkHttp
Stars: ✭ 46 (+64.29%)
Mutual labels:  retrofit, rest-client
Vue Chimera
VueJS reactive RESTful API
Stars: ✭ 160 (+471.43%)
Mutual labels:  restful, rest-client
WanAndroid
wanandroid的Kotlin版,采用Android X
Stars: ✭ 20 (-28.57%)
Mutual labels:  retrofit, retrofit2
Python Ilorest Library Old
Python library for iLO RESTful API
Stars: ✭ 85 (+203.57%)
Mutual labels:  restful, rest-client
light-rest-4j
A RESTful framework built on top of light-4j with both Swagger 2.0 and OpenAPI 3.0 supports
Stars: ✭ 113 (+303.57%)
Mutual labels:  restful, openapi
restofus
Restofus - a cross-platform (REST) API client.
Stars: ✭ 18 (-35.71%)
Mutual labels:  restful, rest-client
uv-index
This is a work-in-progress (🔧️) ultraviolet index viewer app for demonstrating Instant Apps + Kotlin + Dagger + MVP
Stars: ✭ 64 (+128.57%)
Mutual labels:  retrofit, retrofit2

English | 中文版

License: Apache 2 Version: 1.0.0

tuya-connector helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilities. You can put all the focus on business logic without taking care of server-side programming nor relational databases.

demo vedio

Quick start

Integrate Spring Boot

Dependency CurrentEdition:1.0.20

<dependency>
  <groupId>com.tuya</groupId>
  <artifactId>tuya-spring-boot-starter</artifactId>
  <version>#{latest.version}</version>
</dependency>

<!-- Specify the Maven repository URL -->
<repository>
    <id>tuya-maven</id>
    <url>https://maven-other.tuya.com/repository/maven-public/</url>
</repository>

Configuration

# ClientId & SecretKey generated on the Tuya Cloud Development Platform
connector.ak=***
connector.sk=***

region configuration

# region configuration(default region is China if without configuration)
# more details, please check: com.tuya.connector.open.common.constant.TuyaRegion)
connector.region=CN

Usage

Call OpenAPI operations
  1. Create the Connector interface, which is the mapping class of OpenAPI.
public interface DeviceConnector {
    /**
     * query device info by device_id
     * @param deviceId
     * @return
     */
    @GET("/v1.0/devices/{device_id}")
    Device getById(@Path("device_id") String deviceId);
}
  1. Set @ConnectorScan for the class of the Spring Boot application. You can set @EnableMessaging to enable the message subscription capability.
@ConnectorScan(basePackages = "com.xxx.connectors")
@EnableMessaging
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
  1. The Connector interface will be scanned and injected into the Spring container.
@Service
public class DeviceService {
    @Autowired
    private DeviceConnector device;

    public Device getById(String deviceId) {
        return device.getById(deviceId);
    }
}
Subscribe to message events
/**
 * device status data report event
 */
@EventListener
public void statusReportMessage(StatusReportMessage event) {
    log.info("### StatusReport event happened, eventInfo: {}", event);
}

How it works: implement extensions based on the connector framework.

Extension points of OpenAPI

  • ErrorProcessor

You can define the implementation class of ErrorProcessor to handle different error responses. For example, if a token expires, it can be automatically refreshed. The API operation will be tried again with the refreshed token. TokenInvalidErrorProcessor is the built-in implementation class of ErrorProcessor.

The extended ErrorProcessor must be injected into the Spring container to take effect.

  • ContextManager

The connector framework supports TuyaContextManager on which the automatic token refreshing depends. TuyaContextManager can prepare the context before API operations, and manage information including data source connection, tokens, and multilingual text.

  • TokenManager

TuyaTokenManager is the default token management mechanism and implements the TokenManager interface in the connector framework. The token information is cached on the premises.

To manage the token on the premises, you can extend TokenManager and inject it into the Spring container.

  • HeaderProcessor

TuyaHeaderProcessor implements the processing logic of the header for OpenAPI operations, including the required attribute values and signatures.

Extension points of messages

  • MessageDispatcher

TuyaMessageDispatcher implements MessageDispatcher interface for message dispatching in the connector framework. The dispatcher features message ordering and data decryption. It allows you to create specific message types and publish messages based on Spring's event mechanism.

  • MessageEvent

You can add ApplicationListener to listen for required events. The connector framework includes all the Tuya's message event types. The message data contains ciphertext messages and plaintext messages.

Message event BizCode Description
StatusReportMessage statusReport Report data to the cloud.
OnlineMessage online A device is online.
OfflineMessage offline A device is offline.
NameUpdateMessage nameUpdate Modify the device name.
DpNameUpdateMessage dpNameUpdate Modify the name of a data point.
DeleteMessage delete Remove a device.
BindUserMessage bindUser Bind the device to a user account.
UpgradeStatusMessage upgradeStatus The update status.
AutomationExternalActionMessage automationExternalAction Automate an external action.
SceneExecuteMessage sceneExecute Execute a scene.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].