123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package deviceStatus
- import (
- "github.com/gogf/gf/database/gredis"
- )
- const (
- splitStatusKeyPrefix = "device:split:status:"
- mainStatusKeyPrefix = "device:main:status:"
- ffxStatusKeyPrefix = "device:ffx:status:"
- newfanStatusKeyPrefix = "device:newfan:status:"
- ffxInfoKeyPrefix = "device:ffx:info:"
- dataExpires = 7200
- )
- type SplitStatus struct {
- Power int `json:"power"`
- Mode int `json:"mode"`
- FanSpeed int `json:"fan_speed"`
- SetTemp int `json:"set_temp"`
- EnvTemp int `json:"env_temp"`
- EnvCo2 int `json:"env_co2"`
- EnvPm25 int `json:"env_pm25"`
- StatusCode int `json:"status_code"`
- AirMode int `json:"air_mode"`
- AcType int `json:"ac_type"`
- AirType int `json:"air_type"`
- HumType int `json:"hum_type"`
- }
- type DevStatusManager struct {
- redisClient *gredis.Redis
- }
- func NewDevStatusManager(host string, port int) *DevStatusManager {
- red := gredis.New(&gredis.Config{
- Host: host,
- Port: port,
- Db: 14,
- MaxActive: 100,
- })
- mgr := &DevStatusManager{
- redisClient: red,
- }
- return mgr
- }
- 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
- }
- // get status from redis
- result, err := mgr.redisClient.DoVar("GET", key)
- if err != nil {
- return "", err
- }
- return result.String(), nil
- }
- func (mgr *DevStatusManager) GetDeviceInfo(id, productId string) (string, error) {
- var key string
- switch productId {
- case "1pw4ums6ty0d5pyua33f65h100yf45z2":
- key = ffxInfoKeyPrefix + id
- }
- // get status from redis
- result, err := mgr.redisClient.DoVar("GET", key)
- if err != nil {
- return "", err
- }
- return result.String(), nil
- }
|