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

 找回密码
 立即注册
查看: 912|回复: 0

[求助] python语句怎么操作homeAssistant实体

[复制链接]

1

主题

6

帖子

70

积分

注册会员

Rank: 2

积分
70
金钱
63
HASS币
0
发表于 2022-6-18 19:20:02 | 显示全部楼层 |阅读模式
设备是通过易微联加进homeassistant  产生 switch.10000890的实体
1.由于版本更新快 这样的语句是否还有效2.易微联加进去的设备 是不是操作指令不一样

if self.execute_service(entity_id, url, port, headers, act):
                                if not has_execute:
                                    self.say("设备执行成功", cache=True)
                                    has_execute = True
                            else:
                                if not has_execute:
                                    self.say("对不起,设备执行失败", cache=True)                                
                                    has_execute = True


def execute_service(self, entity_id, url, port, headers, act):
        p = json.dumps({"entity_id": entity_id})
        domain = entity_id.split(".")[0]
        s = "/api/services/" + domain + "/"
        url_s = url + ":" + port + s + act        
        request = requests.post(url_s, headers=headers, data=p)
        if format(request.status_code) == "200" or \
           format(request.status_code) == "201":
            return True
        else:
            logger.error(format(request.status_code))
            return False





回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-6 00:56 , Processed in 0.105583 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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