请选择 进入手机版 | 继续访问电脑版

『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1908|回复: 7

[流程系列] undefined 用函数如何判定

[复制链接]

13

主题

220

帖子

644

积分

高级会员

Rank: 4

积分
644
金钱
422
HASS币
0
发表于 2021-9-15 18:25:39 | 显示全部楼层 |阅读模式
本帖最后由 zhouhui920 于 2021-9-15 19:10 编辑

写了个流程卡在判定这个地方了,设备有new_sdata  所以要判定是否有数据,用if怎么判定,我的老是识别不了
    if (msg.data.new_state.attributes.fan_mode != "undefined") {
    if (msg.data.new_state.attributes.fan_mode === "Auto") {msg.data.attributes.fan_mode = `自动`}
    if (msg.data.new_state.attributes.fan_mode === "Low") {msg.data.attributes.fan_mode = `低风`}
    if (msg.data.new_state.attributes.fan_mode === "Medium") {msg.data.attributes.fan_mode = `中等`}
    if (msg.data.new_state.attributes.fan_mode === "High") {msg.data.attributes.fan_mode = `强风`}
    elsf
    if (msg.data.attributes.fan_mode === "Auto") {msg.data.attributes.fan_mode = `自动`}
    if (msg.data.attributes.fan_mode === "Low") {msg.data.attributes.fan_mode = `低风`}
    if (msg.data.attributes.fan_mode === "Medium") {msg.data.attributes.fan_mode = `中等`}
    if (msg.data.attributes.fan_mode === "High") {msg.data.attributes.fan_mode = `强风`}
    }


回复

使用道具 举报

26

主题

2094

帖子

8444

积分

论坛元老

Rank: 8Rank: 8

积分
8444
金钱
6345
HASS币
30

论坛元老

发表于 2021-9-15 19:21:26 | 显示全部楼层
应该是else if这样吧,不是elsf,中间那里
回复

使用道具 举报

13

主题

220

帖子

644

积分

高级会员

Rank: 4

积分
644
金钱
422
HASS币
0
 楼主| 发表于 2021-9-15 19:44:44 | 显示全部楼层
自己找到了,判定原来不要那么准,直接判定是否有new_sdata就行了
回复

使用道具 举报

13

主题

220

帖子

644

积分

高级会员

Rank: 4

积分
644
金钱
422
HASS币
0
 楼主| 发表于 2021-9-15 19:51:17 | 显示全部楼层
情非殇 发表于 2021-9-15 19:21
应该是else if这样吧,不是elsf,中间那里

是else  这个我随便弄的,没留意。搞定了
回复

使用道具 举报

13

主题

220

帖子

644

积分

高级会员

Rank: 4

积分
644
金钱
422
HASS币
0
 楼主| 发表于 2021-9-15 19:52:26 | 显示全部楼层
终于搞定设备监控了,搞了两天了。断断续续的弄,继续美化

home设备播报
二楼空调,冷风模式,25度,低风风速
四楼空调,已经关机了
回复

使用道具 举报

18

主题

353

帖子

2234

积分

金牌会员

North丶

Rank: 6Rank: 6

积分
2234
金钱
1876
HASS币
0

活跃会员卓越贡献

发表于 2021-9-15 20:14:56 | 显示全部楼层
就判断这个还用的着上function嘛,直接一个switch 不就得了简单方便
回复

使用道具 举报

13

主题

220

帖子

644

积分

高级会员

Rank: 4

积分
644
金钱
422
HASS币
0
 楼主| 发表于 2021-9-15 20:42:44 | 显示全部楼层
raspberry0316 发表于 2021-9-15 20:14
就判断这个还用的着上function嘛,直接一个switch 不就得了简单方便

我这个只是给部分代码,里面还有判定非常多,包括设备状态是否在线和关闭等等。如果用switch要哭死,用这个function简单方便随便拷贝修改,switch难搞这么多。
回复

使用道具 举报

0

主题

66

帖子

549

积分

高级会员

Rank: 4

积分
549
金钱
483
HASS币
0
发表于 2021-10-18 21:27:01 来自手机 | 显示全部楼层
判断undefined不要加引号,加了是字符串,要么就typeof 结果是字符串
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-3-19 13:46 , Processed in 0.076052 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表