Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhorne committed Jun 23, 2016
2 parents 69df7dc + 06c5831 commit c73fb29
Show file tree
Hide file tree
Showing 17 changed files with 768 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>0.1.0</string>
<string>1.0.0</string>
<key>ServerApiVersion</key>
<string>1.0</string>
<key>IwsApiVersion</key>
<string>1.0.0</string>
<key>CFBundleDisplayName</key>
<string>Scale Adapters</string>
<string>Adapters</string>
<key>CFBundleIdentifier</key>
<string>com.drjason.temp-adapter</string>
<key>CFBundleVersion</key>
Expand Down
196 changes: 196 additions & 0 deletions Adapters.indigoPlugin/Contents/Server Plugin/Devices.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?xml version="1.0"?>
<Devices>

<Device type="sensor" id="tempConvertedSensor">

<Name>Predefined Scale Adapter</Name>

<ConfigUI>
<Field id="address" type="menu">
<Label>Sensor (state):</Label>
<List class="self" method="get_eligible_sensors"/>
<CallbackMethod>address_changed</CallbackMethod>
</Field>
<Field id="scaleType" type="menu">
<Label>Scale Type:</Label>
<List>
<Option value="length">Length</Option>
<Option value="power">Power</Option>
<Option value="temperature">Temperature</Option>
</List>
<CallbackMethod>scale_type_changed</CallbackMethod>
</Field>
<Field id="nativeScale" type="menu">
<Label>Native Scale:</Label>
<List class="self" filter="" method="get_scales" dynamicReload="true"/>
</Field>
<Field id="desiredScale" type="menu">
<Label>Desired Scale:</Label>
<List class="self" filter="" method="get_scales" dynamicReload="true"/>
</Field>

<Field id="precision" type="menu" defaultValue="1">
<Label>Precision:</Label>
<List>
<Option value="0">1</Option>
<Option value="1">1.0</Option>
<Option value="2">1.00</Option>
<Option value="3">1.000</Option>
</List>
</Field>

<Field id="SupportsSensorValue" type="textfield" hidden="True" defaultValue="True"/>
<Field id="SupportsStatusRequest" type="textfield" hidden="true" defaultValue="False"/>
<Field id="SupportsOnState" type="textfield" hidden="true" defaultValue="False"/>
</ConfigUI>

</Device>

<Device type="sensor" id="linearConvertedSensor">

<Name>Custom Linear Scale Adapter</Name>

<ConfigUI>
<Field id="address" type="menu">
<Label>Sensor (state):</Label>
<List class="self" method="get_eligible_sensors"/>
<CallbackMethod>address_changed</CallbackMethod>
</Field>
<Field id="mathLabel1" type="label" alignWithControl="true">
<Label>Conversion uses the following formula:</Label>
</Field>
<Field id="mathLabel2" type="label" alignWithControl="true">
<Label>result = [(native reading) * multiplier] + offset</Label>
</Field>
<Field id="multiplier" type="textfield" defaultValue="1.0">
<Label>Multiplier:</Label>
</Field>
<Field id="offset" type="textfield" defaultValue="0.0">
<Label>Offset:</Label>
</Field>

<Field id="format" type="textfield" defaultValue="{0:.1f} units">
<Label>Format:</Label>
</Field>
<Field id="formatLabel" type="label" alignWithControl="true">
<Label>Format is specified using the "new style" Python syntax.</Label>
</Field>
<Field id="openFormatHelp" type="button">
<Label></Label>
<Title>Formatting Help</Title>
<CallbackMethod>open_browser_to_python_format_help</CallbackMethod>
</Field>

<Field id="SupportsSensorValue" type="textfield" hidden="True" defaultValue="True"/>
<Field id="SupportsStatusRequest" type="textfield" hidden="true" defaultValue="False"/>
<Field id="SupportsOnState" type="textfield" hidden="true" defaultValue="False"/>
</ConfigUI>

</Device>

<Device type="sensor" id="formulaConvertedSensor">

<Name>Custom Formula Adapter (numeric result)</Name>

<ConfigUI>
<Field id="address" type="menu">
<Label>Sensor (state):</Label>
<List class="self" method="get_eligible_sensors"/>
<CallbackMethod>address_changed</CallbackMethod>
</Field>

<Field id="mathLabel1" type="label" alignWithControl="true">
<Label>Mathematical formula for conversion (use 'x' for input value)</Label>
</Field>
<Field id="formula" type="textfield" defaultValue="(9/5 * x) + 32">
<Label>Formula:</Label>
</Field>
<Field id="numFormulaExample1" type="label" alignWithControl="true" fontSize="small">
<Label>examples:</Label>
</Field>
<Field id="numFormulaExample2" type="label" alignWithControl="true" fontSize="small">
<Label> (9/5 * x) + 32</Label>
</Field>
<Field id="numFormulaExample3" type="label" alignWithControl="true" fontSize="small">
<Label> x ** 2 + 3 * x + 4</Label>
</Field>
<Field id="numFormulaExample4" type="label" alignWithControl="true" fontSize="small">
<Label> 1 if x == 2 else -1</Label>
</Field>
<Field id="numFormulaExample5" type="label" alignWithControl="true" fontSize="small">
<Label> 1 if x == 2 else -1 if x == 3 else 0</Label>
</Field>

<Field id="format" type="textfield" defaultValue="{0:.1f} units">
<Label>Format:</Label>
</Field>
<Field id="formatLabel" type="label" alignWithControl="true">
<Label>Format is specified using the "new style" Python syntax.</Label>
</Field>
<Field id="openFormatHelp" type="button">
<Label></Label>
<Title>Formatting Help</Title>
<CallbackMethod>open_browser_to_python_format_help</CallbackMethod>
</Field>

<Field id="SupportsSensorValue" type="textfield" hidden="True" defaultValue="True"/>
<Field id="SupportsStatusRequest" type="textfield" hidden="true" defaultValue="False"/>
<Field id="SupportsOnState" type="textfield" hidden="true" defaultValue="False"/>
</ConfigUI>

</Device>

<Device type="custom" id="formulaConvertedSensorString">

<Name>Custom Formula Adapter (string result)</Name>

<ConfigUI>
<Field id="address" type="menu">
<Label>Sensor (state):</Label>
<List class="self" method="get_eligible_sensors"/>
<CallbackMethod>address_changed</CallbackMethod>
</Field>

<Field id="mathLabel1" type="label" alignWithControl="true">
<Label>Mathematical formula for conversion (use 'x' for input value)</Label>
</Field>
<Field id="formula" type="textfield" defaultValue="'a' if x == 2 else 'b' if x == 3 else 'c'">
<Label>Formula:</Label>
</Field>
<Field id="strFormulaExample1" type="label" alignWithControl="true" fontSize="small">
<Label>examples:</Label>
</Field>
<Field id="strFormulaExample2" type="label" alignWithControl="true" fontSize="small">
<Label> 'up' if x == 1 else 'down'</Label>
</Field>
<Field id="strFormulaExample3" type="label" alignWithControl="true" fontSize="small">
<Label> 'up' if x == 1 else 'down' if x == 0 else 'stuck'</Label>
</Field>

<Field id="format" type="textfield" defaultValue="code {0}">
<Label>Format:</Label>
</Field>
<Field id="formatLabel" type="label" alignWithControl="true">
<Label>Format is specified using the "new style" Python syntax.</Label>
</Field>
<Field id="openFormatHelp" type="button">
<Label></Label>
<Title>Formatting Help</Title>
<CallbackMethod>open_browser_to_python_format_help</CallbackMethod>
</Field>

</ConfigUI>

<States>
<State id="sensorValue">
<ValueType>String</ValueType>
<TriggerLabel>Sensor Value</TriggerLabel>
<ControlPageLabel>Sensor Value</ControlPageLabel>
</State>
</States>
<UiDisplayStateId>sensorValue</UiDisplayStateId>

</Device>


</Devices>
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ def update_logging(self, is_debug):
self.debug = True
self.log.setLevel(logging.DEBUG)
logging.getLogger("indigo.temp-converter.plugin").setLevel(logging.DEBUG)
logging.getLogger("pyrescaler").setLevel(logging.DEBUG)
self.log.debug("debug logging enabled")
else:
self.log.debug("debug logging disabled")
self.debug=False
self.log.setLevel(logging.INFO)
logging.getLogger("indigo.temp-converter.plugin").setLevel(logging.INFO)
logging.getLogger("pyrescaler").setLevel(logging.INFO)

def startup(self):
self.log.debug(u"startup called")
Expand All @@ -83,6 +85,9 @@ def startup(self):
def shutdown(self):
self.log.debug(u"shutdown called")

def open_browser_to_python_format_help(self, valuesDict=None, typeId="", targetId=0):
self.browserOpen("https://pyformat.info")

def address_changed(self, valuesDict=None, typeId="", targetId=0):
self.log.debug("address_changed")

Expand All @@ -100,21 +105,7 @@ def get_scales(self, filter="", valuesDict=None, typeId="", targetId=0):

def deviceStartComm(self, dev):
self.log.debug("deviceStartComm: %s" % dev.pluginProps["address"])

# added after initial release
if (not "scaleType" in dev.pluginProps) or (not "SupportsSensorValue" in dev.pluginProps) or (not "sensorValue" in dev.states):
self.log.warning("'rebooting' device")
# this seems to be the only thing that will reliably pick up the new
# device type (changed from "custom" to "sensor" since initial release)
dev = indigo.device.changeDeviceTypeId(dev, "tempConvertedSensor")
propCopy = dev.pluginProps
propCopy.update({
"SupportsSensorValue": True,
"SupportsStatusRequest" : False,
"SupportsOnState" : False,
"scaleType" : "temperature",
});
dev.replacePluginPropsOnServer(propCopy)
dev.stateListOrDisplayStateIdChanged() # in case any states added/removed after plugin upgrade

newDevice = SensorAdapter(dev)
self.active_adapters.append(newDevice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

# Internal canonical representation is meters
#
class LengthScale(ScaledMeasurement):
def __init__(self, input_scale=None):
ScaledMeasurement.__init__(self, input_scale)
class LengthScale(PredefinedScaledMeasurement):
def __init__(self, input_scale=None, precision=1):
PredefinedScaledMeasurement.__init__(self, input_scale, precision=precision)
print "%s: %s" % (self.suffix(), self.__class__)

class Inches(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# in -> m
def _to_canonical(self, x):
Expand All @@ -32,8 +32,8 @@ def suffix(self):


class Feet(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# ft -> m
def _to_canonical(self, x):
Expand All @@ -50,8 +50,8 @@ def suffix(self):


class Yards(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# yd -> m
def _to_canonical(self, x):
Expand All @@ -71,8 +71,8 @@ def suffix(self):
# LengthScale.__init__(self, input_scale)

class Miles(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# mi -> m
def _to_canonical(self, x):
Expand All @@ -89,8 +89,8 @@ def suffix(self):


class Centimeters(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# cm -> m
def _to_canonical(self, x):
Expand All @@ -107,8 +107,8 @@ def suffix(self):


class Meters(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# no change
def _to_canonical(self, x):
Expand All @@ -125,8 +125,8 @@ def suffix(self):


class Kilometers(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# km -> m
def _to_canonical(self, x):
Expand All @@ -143,8 +143,8 @@ def suffix(self):


class NauticalMiles(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# nmi -> m
def _to_canonical(self, x):
Expand All @@ -161,8 +161,8 @@ def suffix(self):


class Fathoms(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# fm -> m
def _to_canonical(self, x):
Expand All @@ -179,8 +179,8 @@ def suffix(self):


class Cubits(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# cbt -> m
def _to_canonical(self, x):
Expand All @@ -197,8 +197,8 @@ def suffix(self):


class Hands(LengthScale):
def __init__(self, input_scale=None):
LengthScale.__init__(self, input_scale)
def __init__(self, input_scale=None, precision=1):
LengthScale.__init__(self, input_scale, precision=precision)

# h -> m
def _to_canonical(self, x):
Expand Down
Loading

0 comments on commit c73fb29

Please sign in to comment.