more ip address to variable
This commit is contained in:
parent
dee2077f95
commit
4561ebb552
@ -43,14 +43,6 @@
|
|||||||
"type": "bool",
|
"type": "bool",
|
||||||
"cached": false
|
"cached": false
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "bd0ff439-6ab5-414a-ba6e-9ecef0f7c3f4",
|
|
||||||
"name": "url",
|
|
||||||
"displayName": "Device Address",
|
|
||||||
"displayNameEvent": "Device IP changed",
|
|
||||||
"defaultValue": "0.0.0.0",
|
|
||||||
"type" : "QString"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"displayName": "Power",
|
"displayName": "Power",
|
||||||
"id": "6bb42aa0-2280-408d-89b5-400410abdd73",
|
"id": "6bb42aa0-2280-408d-89b5-400410abdd73",
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import sys
|
|||||||
|
|
||||||
pollTimer = None
|
pollTimer = None
|
||||||
pollFrequency = 30
|
pollFrequency = 30
|
||||||
|
ipMap = {}
|
||||||
|
|
||||||
def discoverThings(info):
|
def discoverThings(info):
|
||||||
logger.log("Discovery started for", info.thingClassId)
|
logger.log("Discovery started for", info.thingClassId)
|
||||||
@ -116,13 +117,11 @@ def findIps():
|
|||||||
sock.close()
|
sock.close()
|
||||||
return discoveredIps
|
return discoveredIps
|
||||||
|
|
||||||
def setupThing(info):
|
def findDeviceIP(airco):
|
||||||
searchSystemId = info.thing.paramValue(aircoThingDeviceIdParamTypeId)
|
searchSystemId = airco.paramValue(aircoThingDeviceIdParamTypeId)
|
||||||
logger.log("setupThing called for", info.thing.name, searchSystemId)
|
|
||||||
|
|
||||||
discoveredIps = findIps()
|
discoveredIps = findIps()
|
||||||
|
foundIp = None
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
for i in range(0, len(discoveredIps)):
|
for i in range(0, len(discoveredIps)):
|
||||||
deviceIp = discoveredIps[i]
|
deviceIp = discoveredIps[i]
|
||||||
aUrl = 'http://' + deviceIp + '/common/basic_info'
|
aUrl = 'http://' + deviceIp + '/common/basic_info'
|
||||||
@ -142,15 +141,24 @@ def setupThing(info):
|
|||||||
if systemId == searchSystemId:
|
if systemId == searchSystemId:
|
||||||
logger.log("Device with IP " + deviceIp + " is the existing device.")
|
logger.log("Device with IP " + deviceIp + " is the existing device.")
|
||||||
found = True
|
found = True
|
||||||
info.thing.setStateValue(aircoUrlStateTypeId, deviceIp)
|
foundIp = deviceIp
|
||||||
|
ipMap[airco] = foundIp
|
||||||
else:
|
else:
|
||||||
logger.log("Device with IP " + deviceIp + " does not appear to be a supported Daikin Airco.")
|
logger.log("Device with IP " + deviceIp + " does not appear to be a supported Daikin Airco.")
|
||||||
if found == True:
|
if found == True:
|
||||||
info.thing.setStateValue(aircoConnectedStateTypeId, True)
|
airco.setStateValue(aircoConnectedStateTypeId, True)
|
||||||
|
else:
|
||||||
|
airco.setStateValue(aircoConnectedStateTypeId, False)
|
||||||
|
return found
|
||||||
|
|
||||||
|
def setupThing(info):
|
||||||
|
searchSystemId = info.thing.paramValue(aircoThingDeviceIdParamTypeId)
|
||||||
|
logger.log("setupThing called for", info.thing.name, searchSystemId)
|
||||||
|
found = findDeviceIP(info.thing)
|
||||||
|
if found == True:
|
||||||
pollAirco(info.thing)
|
pollAirco(info.thing)
|
||||||
info.finish(nymea.ThingErrorNoError)
|
info.finish(nymea.ThingErrorNoError)
|
||||||
else:
|
else:
|
||||||
info.thing.setStateValue(aircoConnectedStateTypeId, False)
|
|
||||||
info.finish(nymea.ThingErrorHardwareFailure, "Error connecting to the device in the network.")
|
info.finish(nymea.ThingErrorHardwareFailure, "Error connecting to the device in the network.")
|
||||||
|
|
||||||
logger.log("Airco added:", info.thing.name)
|
logger.log("Airco added:", info.thing.name)
|
||||||
@ -171,7 +179,8 @@ def setupThing(info):
|
|||||||
|
|
||||||
def pollAirco(info):
|
def pollAirco(info):
|
||||||
global pollFrequency
|
global pollFrequency
|
||||||
deviceIp = info.stateValue(aircoUrlStateTypeId)
|
global ipMap
|
||||||
|
deviceIp = ipMap[info]
|
||||||
logger.log("polling airco", deviceIp, info.name)
|
logger.log("polling airco", deviceIp, info.name)
|
||||||
airco = info
|
airco = info
|
||||||
headers = {'Accept': '*/*'}
|
headers = {'Accept': '*/*'}
|
||||||
@ -197,37 +206,10 @@ def pollAirco(info):
|
|||||||
airco.setStateValue(aircoOutsideTemperatureStateTypeId, outTemp)
|
airco.setStateValue(aircoOutsideTemperatureStateTypeId, outTemp)
|
||||||
else:
|
else:
|
||||||
airco.setStateValue(aircoConnectedStateTypeId, False)
|
airco.setStateValue(aircoConnectedStateTypeId, False)
|
||||||
#device disconnected, did IP change? search again
|
#device disconnected, IP may have changed, so search again
|
||||||
searchSystemId = airco.paramValue(aircoThingDeviceIdParamTypeId)
|
found = findDeviceIP(airco)
|
||||||
discoveredIps = findIps()
|
if found == False:
|
||||||
found = False
|
return
|
||||||
for i in range(0, len(discoveredIps)):
|
|
||||||
deviceIp = discoveredIps[i]
|
|
||||||
aUrl = 'http://' + deviceIp + '/common/basic_info'
|
|
||||||
headers = {'Accept': '*/*'}
|
|
||||||
rr = requests.get(aUrl, headers=headers)
|
|
||||||
pollResponse = rr.text
|
|
||||||
if rr.status_code == requests.codes.ok:
|
|
||||||
logger.log("Device with IP " + deviceIp + " is a supported Daikin Airco.")
|
|
||||||
# get device info
|
|
||||||
splitResponse = pollResponse.split(",")
|
|
||||||
for j in range(0, len(splitResponse)):
|
|
||||||
splitItem = splitResponse[j].split("=")
|
|
||||||
if splitItem[0] == 'id':
|
|
||||||
systemId = splitItem[1]
|
|
||||||
logger.log("Device ID:", systemId)
|
|
||||||
# check if this is the device with the serial number we're looking for
|
|
||||||
if systemId == searchSystemId:
|
|
||||||
logger.log("Device with IP " + deviceIp + " is the existing device.")
|
|
||||||
found = True
|
|
||||||
airco.setStateValue(aircoUrlStateTypeId, deviceIp)
|
|
||||||
else:
|
|
||||||
logger.log("Device with IP " + deviceIp + " does not appear to be a supported Daikin Airco.")
|
|
||||||
if found == True:
|
|
||||||
airco.setStateValue(aircoConnectedStateTypeId, True)
|
|
||||||
else:
|
|
||||||
airco.setStateValue(aircoConnectedStateTypeId, False)
|
|
||||||
return
|
|
||||||
|
|
||||||
# get control info
|
# get control info
|
||||||
# response example:
|
# response example:
|
||||||
@ -322,7 +304,8 @@ def pollService():
|
|||||||
pollAirco(thing)
|
pollAirco(thing)
|
||||||
|
|
||||||
def executeAction(info):
|
def executeAction(info):
|
||||||
deviceIp = info.thing.stateValue(aircoUrlStateTypeId)
|
global ipMap
|
||||||
|
deviceIp = ipMap[info.thing]
|
||||||
logger.log("executeAction called for thing", info.thing.name, deviceIp, info.actionTypeId, info.params)
|
logger.log("executeAction called for thing", info.thing.name, deviceIp, info.actionTypeId, info.params)
|
||||||
headers = {'Accept': '*/*'}
|
headers = {'Accept': '*/*'}
|
||||||
aUrl = 'http://' + deviceIp + '/aircon/get_control_info'
|
aUrl = 'http://' + deviceIp + '/aircon/get_control_info'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user