<?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="customConvertedSensor"> #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>
