|
@@ -4,14 +4,47 @@ import (
|
|
"github.com/gogf/gf/database/gredis"
|
|
"github.com/gogf/gf/database/gredis"
|
|
)
|
|
)
|
|
|
|
|
|
-const (
|
|
|
|
- splitStatusKeyPrefix = "device:split:status:"
|
|
|
|
- mainStatusKeyPrefix = "device:main:status:"
|
|
|
|
- ffxStatusKeyPrefix = "device:ffx:status:"
|
|
|
|
- newfanStatusKeyPrefix = "device:newfan:status:"
|
|
|
|
|
|
+var StatusKey = map[string]string{
|
|
|
|
+ "1pw4umsiq2hd4w7p7o68k69bb0bnlzw0": "device:split:status:",
|
|
|
|
+ "1umcgk0i6m0ch45z0hbgrf8900k4s576": "device:main:status:",
|
|
|
|
+ "1pw4umsgxzld8kwvsm28ndz2f0dktty8": "device:main:status:",
|
|
|
|
+ "1pw4ums6ty0d5pyua33f65h100yf45z2": "device:ffx:status:",
|
|
|
|
+ "1pw4umsgxzlda7g4p1zcd6v2m0ukxftv": "device:newfan:status:",
|
|
|
|
+ "1pw4umsimu4dcvsvph9iepl300r7d7v9": "device:wifi:status:",
|
|
|
|
+ "1pw4umsgxzldbd8wyvknk623f0e2obdb": "device:fp:status:",
|
|
|
|
+ "1pw4umsgxzld9eikeie2o822g0hy0yyn": "device:th4G:status:",
|
|
|
|
+ "1pw4umsiq2hd4hplv2mhp9mba0l1bv87": "device:twb:status:",
|
|
|
|
+ "1pw4umsgxzldbd6c46r0qpn3e0jekjgj": "device:wj:status:",
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var InfoKey = map[string]string{
|
|
|
|
+ "1pw4umsiq2hd4w7p7o68k69bb0bnlzw0": "device:split:info:",
|
|
|
|
+ "1umcgk0i6m0ch45z0hbgrf8900k4s576": "device:main:info:",
|
|
|
|
+ "1pw4umsgxzld8kwvsm28ndz2f0dktty8": "device:main:info:",
|
|
|
|
+ "1pw4ums6ty0d5pyua33f65h100yf45z2": "device:ffx:info:",
|
|
|
|
+ "1pw4umsgxzlda7g4p1zcd6v2m0ukxftv": "device:newfan:info:",
|
|
|
|
+ "1pw4umsimu4dcvsvph9iepl300r7d7v9": "device:wifi:info:",
|
|
|
|
+ "1pw4umsgxzldbd8wyvknk623f0e2obdb": "device:fp:info:",
|
|
|
|
+ "1pw4umsgxzld9eikeie2o822g0hy0yyn": "device:th4G:info:",
|
|
|
|
+ "1pw4umsiq2hd4hplv2mhp9mba0l1bv87": "device:twb:info:",
|
|
|
|
+ "1pw4umsgxzldbd6c46r0qpn3e0jekjgj": "device:wj:info:",
|
|
|
|
+}
|
|
|
|
|
|
- ffxInfoKeyPrefix = "device:ffx:info:"
|
|
|
|
- dataExpires = 7200
|
|
|
|
|
|
+var EventKey = map[string]string{
|
|
|
|
+ "1pw4umsiq2hd4w7p7o68k69bb0bnlzw0": "device:split:event:",
|
|
|
|
+ "1umcgk0i6m0ch45z0hbgrf8900k4s576": "device:main:event:",
|
|
|
|
+ "1pw4umsgxzld8kwvsm28ndz2f0dktty8": "device:main:event:",
|
|
|
|
+ "1pw4ums6ty0d5pyua33f65h100yf45z2": "device:ffx:event:",
|
|
|
|
+ "1pw4umsgxzlda7g4p1zcd6v2m0ukxftv": "device:newfan:event:",
|
|
|
|
+ "1pw4umsimu4dcvsvph9iepl300r7d7v9": "device:wifi:event:",
|
|
|
|
+ "1pw4umsgxzldbd8wyvknk623f0e2obdb": "device:fp:event:",
|
|
|
|
+ "1pw4umsgxzld9eikeie2o822g0hy0yyn": "device:th4G:event:",
|
|
|
|
+ "1pw4umsiq2hd4hplv2mhp9mba0l1bv87": "device:twb:event:",
|
|
|
|
+ "1pw4umsgxzldbd6c46r0qpn3e0jekjgj": "device:wj:event:",
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ dataExpires = 7200
|
|
)
|
|
)
|
|
|
|
|
|
type SplitStatus struct {
|
|
type SplitStatus struct {
|
|
@@ -47,17 +80,7 @@ func NewDevStatusManager(host string, port int) *DevStatusManager {
|
|
}
|
|
}
|
|
|
|
|
|
func (mgr *DevStatusManager) GetDeviceStatus(id, productId string) (string, error) {
|
|
func (mgr *DevStatusManager) GetDeviceStatus(id, productId string) (string, error) {
|
|
- var key string
|
|
|
|
- switch productId {
|
|
|
|
- case "1pw4umsiq2hd4w7p7o68k69bb0bnlzw0":
|
|
|
|
- key = splitStatusKeyPrefix + id
|
|
|
|
- case "1pw4umsgxzlda7g4p1zcd6v2m0ukxftv":
|
|
|
|
- key = newfanStatusKeyPrefix + id
|
|
|
|
- case "1pw4ums6ty0d5pyua33f65h100yf45z2":
|
|
|
|
- key = ffxStatusKeyPrefix + id
|
|
|
|
- default:
|
|
|
|
- key = mainStatusKeyPrefix + id
|
|
|
|
- }
|
|
|
|
|
|
+ key := StatusKey[productId] + id
|
|
// get status from redis
|
|
// get status from redis
|
|
result, err := mgr.redisClient.DoVar("GET", key)
|
|
result, err := mgr.redisClient.DoVar("GET", key)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -67,11 +90,7 @@ func (mgr *DevStatusManager) GetDeviceStatus(id, productId string) (string, erro
|
|
}
|
|
}
|
|
|
|
|
|
func (mgr *DevStatusManager) GetDeviceInfo(id, productId string) (string, error) {
|
|
func (mgr *DevStatusManager) GetDeviceInfo(id, productId string) (string, error) {
|
|
- var key string
|
|
|
|
- switch productId {
|
|
|
|
- case "1pw4ums6ty0d5pyua33f65h100yf45z2":
|
|
|
|
- key = ffxInfoKeyPrefix + id
|
|
|
|
- }
|
|
|
|
|
|
+ key := InfoKey[productId] + id
|
|
// get status from redis
|
|
// get status from redis
|
|
result, err := mgr.redisClient.DoVar("GET", key)
|
|
result, err := mgr.redisClient.DoVar("GET", key)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -111,3 +130,12 @@ func (mgr *DevStatusManager) SetWeatherInfo(location string, info string) error
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (mgr *DevStatusManager) GetDeviceEvent(id, productId string) (string, error) {
|
|
|
|
+ key := EventKey[productId] + id
|
|
|
|
+ result, err := mgr.redisClient.DoVar("GET", key)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ return result.String(), nil
|
|
|
|
+}
|