pythonを使って玄関のカギを開ける。

pythonを使って玄関のカギを開ける。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/1113000d-6fc6-61e7-1ce0-e33d3097fd0f.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/59c78e81-0290-61ad-b7de-4e26d7dbd945.png)
#セサミ mini スマートロック ＋ WiFiアクセスポイント 価格¥14,500 
#初期設定
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/9ae9ae42-00f0-c6fd-dc28-b539a9e73f15.png)


#Keyをもらう
**https://my.candyhouse.co/
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/5c6c8069-5f37-a835-2976-44927377f08c.png)

##実際のサンプルプログラム
```sesami.py
import requests,json,time
"""
Sesame API Y.Hirata 2020/05/30
"""
class SesamiApi:
    list=[]
    stat=[]
    device_id=""
    task_id=""
    def __init__(self,header):
        self.Header=header
    """GetSesameList"""
    def GetSesameList(self):
        self.list=json.loads(requests.get('https://api.candyhouse.co/public/sesames',headers= {'Authorization':self.Header}).text)
        return self.list
    """GetSesameStatus"""
    def GetSesameStatus(self,nickname):
        self.stat=[]
        if nickname==None:
            for x in self.list:
                self.stat.append(json.loads(requests.get('https://api.candyhouse.co/public/sesame/%s'%x["device_id"],headers= {'Authorization':self.Header}).text))
            return self.stat
        else:
            for x in self.list:
                if nickname==x["nickname"]:
                    self.device_id=x["device_id"]
                    return json.loads(requests.get('https://api.candyhouse.co/public/sesame/%s'%self.device_id,headers={'Authorization':self.Header}).text)
    """Control Sesame Unlock"""
    def ControlSesameUnLock(self):
        headers = {'Authorization': self.Header,'Content-Type': 'application/json'}
        data = '{"command":"unlock"}'
        js = json.loads(requests.post('https://api.candyhouse.co/public/sesame/%s'%self.device_id, headers=headers, data=data).text)
        self.task_id=js['task_id']
        return self.task_id
    """Control Sesame lock"""
    def ControlSesameLock(self):
        headers = {'Authorization': self.Header,'Content-Type': 'application/json'}
        data = '{"command":"lock"}'
        js = json.loads(requests.post('https://api.candyhouse.co/public/sesame/%s'%self.device_id, headers=headers, data=data).text)
        self.task_id=js['task_id']
        return self.task_id

    """Query Execution Result"""
    def QueryExecutionResult(self,task_id):
        params = (('task_id', task_id),)
        return json.loads( requests.get('https://api.candyhouse.co/public/action-result', headers={'Authorization':self.Header}, params=params).text)
##登録してkeyをもらう
key='CzAHJ-OdR7mjH2iehLK8lKU.....O0VVJdeRFZq5nhy6TJ3Jc1KPB.........'
############## Sample program##########################################
s=SesamiApi(key)
res=s.GetSesameList()　##リスト形式で登録してある電気錠の情報を求める
print(res)
res=s.GetSesameStatus("玄関")　##玄関のステータスを求めろ
print(res)
id=s.ControlSesameUnLock()　##開錠する。
print(id)
############## response ################################################
[{"device_id": "ca0001ce-............", "serial": "E7055.....", "nickname": "玄関"}]
{"locked": true, "battery": 100, "responsive": true}
{"task_id": "7c756ae1-ff14-4cb9-a314-d2afe0dec3b2"}
```