Skip to content

Commit

Permalink
py3
Browse files Browse the repository at this point in the history
  • Loading branch information
kmarkley committed Jul 17, 2022
1 parent 9560167 commit a21e7e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This plugin co-opts Indigo thermostat devices as general purpose threshold-respo
Any numerical device state or variable value can be used as input (analogous to temperature), and devices can be switched on/off or action groups executed in response to the input value crossing a high threshold (analogous to cooling) and or low threshold (analogous to heating).

Example uses†:

* Thermostat
* Humidistat
* Lumistat
Expand Down
4 changes: 2 additions & 2 deletions Unistat.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>0.0.5</string>
<string>0.1.0</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<string>3.0</string>
<key>IwsApiVersion</key>
<string>1.0.0</string>
<key>CFBundleDisplayName</key>
Expand Down
57 changes: 28 additions & 29 deletions Unistat.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) 2016, Perceptive Automation, LLC. All rights reserved.
# http://www.indigodomo.com

import indigo
import indigo #noqa
import time

# Note the "indigo" module is automatically imported and made available inside
Expand Down Expand Up @@ -161,7 +161,7 @@ def actionControlThermostat(self, action, dev):

###### OTHER ACTIONS ######
else:
self.logger.debug(u'"{}" {} action not available'.format(dev.name, unicode(action.thermostatAction)))
self.logger.debug(f'"{dev.name}" {action.thermostatAction} action not available')

#-------------------------------------------------------------------------------
# General Action callback
Expand All @@ -175,7 +175,7 @@ def actionControlUniversal(self, action, dev):

###### OTHER ACTIONS ######
else:
self.logger.debug(u'"{}" {} action not available'.format(dev.name, unicode(action.deviceAction)))
self.logger.debug(f'"{dev.name}" {action.deviceAction} action not available')


#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -236,18 +236,18 @@ def __init__(self, instance, logger):
self.inputStateKey = None
self.inputVariableId = int(self.props['inputVariable'])
else:
self.logger.error(u'"{}" input init failed'.format(self.name))
self.logger.error(f'"{self.name}" input init failed')
raise

self.halfband = float(self.props.get('deadband', 1.0))/2.0
self.units = self.props.get('inputUnits',u'')
self.units = self.props.get('inputUnits','')
self.decimals = int(self.props.get('inputDecimals', 1))

self.modeNameMap = {
indigo.kHvacMode.Off : self.props.get('modeNameOff', u'Off' ),
indigo.kHvacMode.Heat : self.props.get('modeNameHeat', u'Heat'),
indigo.kHvacMode.Cool : self.props.get('modeNameCool', u'Cool'),
indigo.kHvacMode.HeatCool : self.props.get('modeNameAuto', u'Auto'),
indigo.kHvacMode.Off : self.props.get('modeNameOff', 'Off' ),
indigo.kHvacMode.Heat : self.props.get('modeNameHeat', 'Heat'),
indigo.kHvacMode.Cool : self.props.get('modeNameCool', 'Cool'),
indigo.kHvacMode.HeatCool : self.props.get('modeNameAuto', 'Auto'),
}

self.requestTemperature()
Expand All @@ -258,18 +258,17 @@ def requestTemperature(self):
try:
self.temperatureInput = indigo.devices[self.inputDeviceId].states[self.inputStateKey]
except KeyError:
self.logger.error(u'Input device {} does not exist. Reconfigure "{}".'.format(self.inputDeviceId,self.name))
self.logger.error(f'Input device {self.inputDeviceId} does not exist. Reconfigure "{self.name}".')
elif self.inputVariableId:
try:
self.temperatureInput = indigo.variables[self.inputVariableId].value
except KeyError:
self.logger.error(u'Input variable {} does not exist. Reconfigure "{}".'.format(self.inputVariableId,self.name))
self.logger.error(f'Input variable {self.inputVariableId} does not exist. Reconfigure "{self.name}".')

#-------------------------------------------------------------------------------
def selfDeviceUpdated(self, newDev):
self.dev = newDev
self.logger.debug(u'"{}" evaluate equipment state [in:{} hi:{}, lo:{}, hb:{}]'.format(
self.name, self.temperatureInput, self.setpointCool, self.setpointHeat, self.halfband))
self.logger.debug(f'"{self.name}" evaluate equipment state [in:{self.temperatureInput} hi:{self.setpointCool}, lo:{self.setpointHeat}, hb:{self.halfband}]')

# evaluate cool equipment state
if self.hvacCoolerEnabled:
Expand Down Expand Up @@ -302,7 +301,7 @@ def inputVariableUpdated(self, newVar):
#-------------------------------------------------------------------------------
def getModeName(self, mode=None):
if mode is None: mode = self.hvacOperationMode
return self.modeNameMap.get(mode, u'Unknown')
return self.modeNameMap.get(mode, 'Unknown')

#-------------------------------------------------------------------------------
# properties
Expand All @@ -312,10 +311,10 @@ def _temperatureInputGet(self):
def _temperatureInputSet(self, temp):
if temp != self.temperatureInput:
try:
self.dev.updateStateOnServer('temperatureInput1', float(temp), uiValue=u'{:.{}f}{}'.format(float(temp),self.decimals,self.units))
self.logger.debug(u'"{}" received input {:.{}f}{}'.format(self.name, float(temp),self.decimals,self.units))
self.dev.updateStateOnServer('temperatureInput1', float(temp), uiValue=f'{float(temp):.{self.decimals}f}{self.units}')
self.logger.debug(f'"{self.name}" received input {float(temp):.{self.decimals}f}{self.units}')
except ValueError:
self.logger.error(u'"{}" received invalid input "{}" ({})'.format(self.name, temp, type(temp)))
self.logger.error(f'"{self.name}" received invalid input "{temp}" ({type(temp)})')
temperatureInput = property(_temperatureInputGet,_temperatureInputSet)

#-------------------------------------------------------------------------------
Expand All @@ -325,9 +324,9 @@ def _hvacOperationModeSet(self, mode):
if mode in range(4):
if mode != self.hvacOperationMode:
self.dev.updateStateOnServer('hvacOperationMode', mode, uiValue=self.getModeName(mode))
self.logger.info(u'"{}" mode now {}'.format(self.name, self.getModeName(mode)))
self.logger.info(f'"{self.name}" mode now {self.getModeName(mode)}')
else:
self.logger.error(u'"{}" program mode not supported'.format(self.name))
self.logger.error(f'"{self.name}" program mode not supported')
hvacOperationMode = property(_hvacOperationModeGet,_hvacOperationModeSet)

#-------------------------------------------------------------------------------
Expand All @@ -339,10 +338,10 @@ def _setpointCoolGet(self):
def _setpointCoolSet(self, setpoint):
if self.props['SupportsCoolSetpoint']:
if setpoint != self.setpointCool:
self.dev.updateStateOnServer('setpointCool', setpoint, uiValue=u'{:.{}f}{}'.format(float(setpoint), self.decimals, self.units))
self.logger.info(u'"{}" {} setpoint now {}{}'.format(self.name, self.getModeName(indigo.kHvacMode.Cool), setpoint, self.units))
self.dev.updateStateOnServer('setpointCool', setpoint, uiValue=f'{float(setpoint):.{self.decimals}f}{self.units}')
self.logger.info(f'"{self.name}" {self.getModeName(indigo.kHvacMode.Cool)} setpoint now {setpoint}{self.units}')
else:
self.logger.error(u'"{}" {} setpoint not supported'.format(self.name, self.getModeName(indigo.kHvacMode.Cool)))
self.logger.error(f'"{self.name}" {self.getModeName(indigo.kHvacMode.Cool)} setpoint not supported')
setpointCool = property(_setpointCoolGet,_setpointCoolSet)

#-------------------------------------------------------------------------------
Expand All @@ -354,10 +353,10 @@ def _setpointHeatGet(self):
def _setpointHeatSet(self, setpoint):
if self.props['SupportsHeatSetpoint']:
if setpoint != self.setpointHeat:
self.dev.updateStateOnServer('setpointHeat', setpoint, uiValue=u'{:.{}f}{}'.format(float(setpoint), self.decimals, self.units))
self.logger.info(u'"{}" {} setpoint now {}{}'.format(self.name, self.getModeName(indigo.kHvacMode.Heat), setpoint, self.units))
self.dev.updateStateOnServer('setpointHeat', setpoint, uiValue=f'{float(setpoint):.{self.decimals}f}{self.units}')
self.logger.info(f'"{self.name}" {self.getModeName(indigo.kHvacMode.Heat)} setpoint now {setpoint}{self.units}')
else:
self.logger.error(u'"{}" {} setpoint not supported'.format(self.name, self.getModeName(indigo.kHvacMode.Heat)))
self.logger.error(f'"{self.name}" {self.getModeName(indigo.kHvacMode.Heat)} setpoint not supported')
setpointHeat = property(_setpointHeatGet,_setpointHeatSet)

#-------------------------------------------------------------------------------
Expand All @@ -366,7 +365,7 @@ def _hvacCoolerIsOnGet(self):
def _hvacCoolerIsOnSet(self, onState):
if onState != self.hvacCoolerIsOn:
self.dev.updateStateOnServer('hvacCoolerIsOn', onState)
self.logger.info(u'"{}" {} equipment now {}'.format(self.name, self.getModeName(indigo.kHvacMode.Cool), ['off','on'][onState]))
self.logger.info(f'"{self.name}" {self.getModeName(indigo.kHvacMode.Cool)} equipment now {["off","on"][onState]}')
self.setCoolerEquipmentState(onState)
hvacCoolerIsOn = property(_hvacCoolerIsOnGet,_hvacCoolerIsOnSet)

Expand All @@ -376,7 +375,7 @@ def _hvacHeaterIsOnGet(self):
def _hvacHeaterIsOnSet(self, onState):
if onState != self.hvacHeaterIsOn:
self.dev.updateStateOnServer('hvacHeaterIsOn', onState)
self.logger.info(u'"{}" {} equipment now {}'.format(self.name, self.getModeName(indigo.kHvacMode.Cool), ['off','on'][onState]))
self.logger.info(f'"{self.name}" {self.getModeName(indigo.kHvacMode.Cool)} equipment now {["off","on"][onState]}')
self.setHeaterEquipmentState(onState)
hvacHeaterIsOn = property(_hvacHeaterIsOnGet,_hvacHeaterIsOnSet)

Expand Down Expand Up @@ -447,7 +446,7 @@ def _setEquipmentState(self, deviceIdList, onState):
else:
self.relayControlFunction[onState](device)
except KeyError:
self.logger.error(u'Device {} does not exist. Reconfigure "{}".'.format(deviceId,self.name))
self.logger.error(f'Device {deviceId} does not exist. Reconfigure "{self.name}".')

###############################################################################
class ActionGroupUnistat(UnistatBase):
Expand Down Expand Up @@ -481,7 +480,7 @@ def _executeAction(self, actionId):
try:
indigo.actionGroup.execute(actionId)
except KeyError:
self.logger.error(u'Action Group {} does not exist. Reconfigure device "{}".'.format(actionId,self.name))
self.logger.error(f'Action Group {actionId} does not exist. Reconfigure device "{self.name}".')


################################################################################
Expand Down

0 comments on commit a21e7e1

Please sign in to comment.