Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-slx committed Aug 1, 2021
2 parents 7039937 + 030cda1 commit f455eb9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 42 deletions.
4 changes: 2 additions & 2 deletions bin/user/weatherlink_live/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from weewx.engine import InitializationError

DRIVER_NAME = "WeatherLinkLive"
DRIVER_VERSION = "1.0.8"
DRIVER_VERSION = "1.0.9"

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -258,7 +258,7 @@ def default_stanza(self):
# Mapping of transmitter ids to WeeWX records
# Default for Vantage Pro2
mapping = th:1, th_indoor, baro, rain:1, wind:1, thw:1:appTemp, windchill:1, battery
mapping = th:1, th_indoor, baro, rain:1, wind:1, thw:1:appTemp, windchill:1, battery:1:outTemp:rain:wind
"""

def modify_config(self, config_dict):
Expand Down
7 changes: 6 additions & 1 deletion bin/user/weatherlink_live/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ def __repr__(self):

def create_mappers(self) -> List[AbstractMapping]:
used_record_keys = []
return [self._create_mapper(source_opts, used_record_keys) for source_opts in self.mappings]
mappers = []
for source_opts in self.mappings:
mapper = self._create_mapper(source_opts, used_record_keys)
mappers.append(mapper)
used_record_keys.extend(mapper.targets.values())
return mappers

def _create_mapper(self, source_opts: List[str], used_map_targets: List[str]) -> AbstractMapping:
type = source_opts[0]
Expand Down
25 changes: 18 additions & 7 deletions bin/user/weatherlink_live/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,23 @@ def _do_mapping(self, packet: DavisConditionsPacket, record: dict):

class BatteryStatusMapping(AbstractMapping):
def __init__(self, mapping_opts: list, used_map_targets: list, log_success: bool = False, log_error: bool = True):
super().__init__({}, mapping_opts, used_map_targets, log_success, log_error)
super().__init__({
'battery': targets.BATTERY_STATUS
}, mapping_opts, used_map_targets, log_success, log_error)

self.tx_id = self._parse_option_int(mapping_opts, 0)

further_opts = mapping_opts[1:]
try:
self.further_targets = [targets.BATTERY_STATUS_NAMED[key] for key in further_opts]
except KeyError as e:
raise KeyError("Invalid battery remap target") from e

def _do_mapping(self, packet: DavisConditionsPacket, record: dict):
for tx in targets.BATTERY_STATUS.keys():
try:
self._set_record_entry(record, targets.BATTERY_STATUS[tx],
packet.get_observation(KEY_BATTERY_FLAG, tx=tx))
except NotInPacket:
pass # Continue with other transmitters
battery_num = self.targets['battery']

self._set_record_entry(record, battery_num,
packet.get_observation(KEY_BATTERY_FLAG, tx=self.tx_id))
for target in self.further_targets:
self._set_record_entry(record, target,
packet.get_observation(KEY_BATTERY_FLAG, tx=self.tx_id))
21 changes: 13 additions & 8 deletions bin/user/weatherlink_live/static/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@
PM10 = ["pm10_0"]

# Battery status
BATTERY_STATUS = {1: 'batteryStatus1',
2: 'batteryStatus2',
3: 'batteryStatus3',
4: 'batteryStatus4',
5: 'batteryStatus5',
6: 'batteryStatus6',
7: 'batteryStatus7',
8: 'batteryStatus8'}
BATTERY_STATUS = ['batteryStatus1',
'batteryStatus2',
'batteryStatus3',
'batteryStatus4',
'batteryStatus5',
'batteryStatus6',
'batteryStatus7',
'batteryStatus8']
BATTERY_STATUS_NAMED = {'outTemp': 'outTempBatteryStatus',
'rain': 'rainBatteryStatus',
'tx': 'txBatteryStatus',
'uv': 'uvBatteryStatus',
'wind': 'windBatteryStatus'}
8 changes: 8 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,11 @@ The driver only uses it for the rate of the rain collector spoon tripping.

- **Fix broken temperature-only mapping**

## Version 1.0.9

- **Allow named mapping targets for battery status**

`battery` mapping now maps one transmitter only, but supports mapping to WeeWX's standard named battery status fields additionally to the numeric ones.

- **Fix mapping targets being used multiple times**

2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WeatherLinkLiveInstaller(ExtensionInstaller):
def __init__(self):
super(WeatherLinkLiveInstaller, self).__init__(
name='weatherlink-live',
version="1.0.8",
version="1.0.9",
description='WeeWX driver for Davis WeatherLink Live.',
author="Michael Schantl",
author_email="floss@schantl-lx.at",
Expand Down
44 changes: 22 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The units of all additionally defined observations are converted as specified in
host = weatherlink

# Mapping of transmitter ids
mapping = th:1, th_indoor, baro, rain:1, wind:1, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, battery
mapping = th:1, th_indoor, baro, rain:1, wind:1, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, battery:1:outTemp:rain:wind:uv

[DataBindings]

Expand Down Expand Up @@ -161,23 +161,23 @@ List of sensors and their ids to import into WeeWX. Each mapping definition cons

### Available mappings

| Mapping name | Parameters | Description |
| ---------------------------------------------- | -------------------------------- | ------------------------------------------------------------ |
| **`t`** (temperature) | Sensor id | Maps outside temperature (no humidity) |
| **`th`** (temperature, humidity) | Sensor id | Maps outside temperature, humidity, heat index, dew point and wet bulb temperature |
| **`wind`** | Sensor id | Maps wind speed and direction to LOOP speed and direction.<br />An additional service then finds the maximum wind speed during the archive interval and assigns this speed and the respective direction to the gust observations. |
| **`rain`** | Sensor id | Maps rain amount and rate as well as count of spoon trips, rate of spoon trips and size of spoon.<br />Differential rain amount is calculated from daily rain measurement. |
| **`solar`** (solar radiation) | Sensor id | Maps solar radiation |
| **`uv`** (UV index) | Sensor id | Maps UV index |
| **`windchill`** (wind chill) | Sensor id | Maps wind chill as reported by the respective transmitter.<br />_**Note:** Only available when thermometer and anemometer are connected to the same transmitter._ |
| **`thw`** (THW index) | Sensor id, **Option:** `appTemp` | Maps THW (temperature, humidity, wind) index as reported by the respective transmitter.<br />_**Note:** Only available when thermometer, hygrometer and anemometer are connected to the same transmitter.<br />**Option `appTemp`:** When this option is set (see examples), the THW index value is additionally mapped to the `appTemp` field available in the WeeWX default schema. |
| **`thsw`** (THSW index) | Sensor id, **Option:** `appTemp` | Maps THSW (temperature, humidity, solar, wind) index as reported by the respective transmitter.<br />_**Note:** Only available when thermometer, hygrometer, pyranometer and anemometer are connected to the same transmitter._<br />**Option `appTemp`:** When this option is set (see examples), the THSW index value is additionally mapped to the `appTemp` field available in the WeeWX default schema. |
| **`soil_temp`** (soil temperature) | Sensor id, Sensor number | Maps soil temperature sensors from soil/leaf stations. |
| **`soil_moist`** (soil moisture) | Sensor id, Sensor number | Maps soil moisture sensors from soil/leaf stations. |
| **`leaf_wet`** (leaf wetness) | Sensor id, Sensor number | Maps leaf wetness sensors from soil/leaf stations. |
| **`th_indoor`** (indoor temperature, humidity) | _none_ | Maps indoor temperature, humidity, heat index and dew point as measured by the WLL itself |
| **`baro`** (barometer) | _none_ | Maps station (absolute) and sea-level pressure as measured/calculated by the WLL itself |
| **`battery`** | _none_ | Maps the battery status indicator flag of all connected transmitters to the fields `batteryStatus1` to `batteryStatus8`. I.e. the value of transmitter 1 is mapped to `batteryStatus1`, transmitter 2 to `batteryStatus2` and so on.<br />**`0`** = Battery OK; **`1`** = Battery low |
| Mapping name | Parameters | Description |
| ---------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| **`t`** (temperature) | Sensor id | Maps outside temperature (no humidity) |
| **`th`** (temperature, humidity) | Sensor id | Maps outside temperature, humidity, heat index, dew point and wet bulb temperature |
| **`wind`** | Sensor id | Maps wind speed and direction to LOOP speed and direction.<br />An additional service then finds the maximum wind speed during the archive interval and assigns this speed and the respective direction to the gust observations. |
| **`rain`** | Sensor id | Maps rain amount and rate as well as count of spoon trips, rate of spoon trips and size of spoon.<br />Differential rain amount is calculated from daily rain measurement. |
| **`solar`** (solar radiation) | Sensor id | Maps solar radiation |
| **`uv`** (UV index) | Sensor id | Maps UV index |
| **`windchill`** (wind chill) | Sensor id | Maps wind chill as reported by the respective transmitter.<br />_**Note:** Only available when thermometer and anemometer are connected to the same transmitter._ |
| **`thw`** (THW index) | Sensor id,<br/>**Option:** `appTemp` | Maps THW (temperature, humidity, wind) index as reported by the respective transmitter.<br />_**Note:** Only available when thermometer, hygrometer and anemometer are connected to the same transmitter.<br />**Option `appTemp`:** When this option is set (see examples), the THW index value is additionally mapped to the `appTemp` field available in the WeeWX default schema. |
| **`thsw`** (THSW index) | Sensor id,<br/>**Option:** `appTemp` | Maps THSW (temperature, humidity, solar, wind) index as reported by the respective transmitter.<br />_**Note:** Only available when thermometer, hygrometer, pyranometer and anemometer are connected to the same transmitter._<br />**Option `appTemp`:** When this option is set (see examples), the THSW index value is additionally mapped to the `appTemp` field available in the WeeWX default schema. |
| **`soil_temp`** (soil temperature) | Sensor id, Sensor number | Maps soil temperature sensors from soil/leaf stations. |
| **`soil_moist`** (soil moisture) | Sensor id, Sensor number | Maps soil moisture sensors from soil/leaf stations. |
| **`leaf_wet`** (leaf wetness) | Sensor id, Sensor number | Maps leaf wetness sensors from soil/leaf stations. |
| **`th_indoor`** (indoor temperature, humidity) | _none_ | Maps indoor temperature, humidity, heat index and dew point as measured by the WLL itself |
| **`baro`** (barometer) | _none_ | Maps station (absolute) and sea-level pressure as measured/calculated by the WLL itself |
| **`battery`** | Sensor id, <br/>**Options:** `outTemp`, `rain`, `tx`, `uv`, `wind` | Maps the battery status indicator flag the specified transmitter to the fields `batteryStatus1` to `batteryStatus8`.<br />**Options:** One or more options can be specified to map the battery status of the respective transmitter to the named battery field.<br />_`outTemp`_ = `outTempBatteryStatus`; _`rain`_ = `rainBatteryStatus`; _`tx`_ = `txBatteryStatus`; _`uv`_ = `uvBatteryStatus`; _`wind`_ = `windBatteryStatus`<br />**`0`** = Battery OK; **`1`** = Battery low |

### Mapping examples

Expand All @@ -186,7 +186,7 @@ List of sensors and their ids to import into WeeWX. Each mapping definition cons
This example is a valid mapping for a factory-default Vantage2 Pro Plus. All sensors are connected to the main ISS transmitter set to id 1.

```ini
mapping = th:1, th_indoor, baro, rain:1, wind:1, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, battery
mapping = th:1, th_indoor, baro, rain:1, wind:1, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, battery:1:outTemp:rain:wind:uv
```

#### Vantage2 Pro Plus with additional anemometer transmitter
Expand All @@ -196,7 +196,7 @@ Same as above, except the wind sensor is connected to a separate transmitter wit
Note that there is a configuration option on WeatherLink.com to import the wind measurement into the measurements of the main transmitter. If you enable this, the wind chill, THW and THSW values will still be calculated. Otherwise they should be removed from the mapping.

```ini
mapping = th:1, th_indoor, baro, rain:1, wind:2, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, battery
mapping = th:1, th_indoor, baro, rain:1, wind:2, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, battery:1:outTemp:rain:uv, battery:2:wind
```

#### Vantage2 Pro Plus with separate transmitter for wind, solar and UV
Expand All @@ -206,7 +206,7 @@ Same as above, except the solar and UV sensors are also connected to the separat
Note that THSW will not be calculated anymore since the solar sensor is now on a separate transmitter and unlike the wind measurements there's no configuration option.

```ini
mapping = th:1, th_indoor, baro, rain:1, wind:2, uv:2, solar:2, thw:1:appTemp, windchill:1, battery
mapping = th:1, th_indoor, baro, rain:1, wind:2, uv:2, solar:2, thw:1:appTemp, windchill:1, battery:1:outTemp:rain, battery:2:wind:uv
```

#### Vantage2 Pro Plus with soil/leaf station
Expand All @@ -216,7 +216,7 @@ Same as the first example with an additional soil/leaf station. The agriculture
Note that the ordering of the mapping matters: Mappings named earlier are mapped to the "lower-numbered" database columns. Remember this fact if you wish to add additional sensors later on.

```ini
mapping = th:1, th_indoor, baro, rain:1, wind:1, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, soil_temp:2:1, soil_temp:2:2, soil_temp:2:3, soil_temp:2:4, soil_moist:2:1, soil_moist:2:2, soil_moist:2:3, soil_moist:2:4, leaf_wet:2:1, lef_wet:2:2, battery
mapping = th:1, th_indoor, baro, rain:1, wind:1, uv:1, solar:1, thw:1, thsw:1:appTemp, windchill:1, soil_temp:2:1, soil_temp:2:2, soil_temp:2:3, soil_temp:2:4, soil_moist:2:1, soil_moist:2:2, soil_moist:2:3, soil_moist:2:4, leaf_wet:2:1, lef_wet:2:2, battery:1:outTemp:wind, battery:2:tx
```

## Contribution
Expand Down
2 changes: 1 addition & 1 deletion testing/conf/weewx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ version = 4.5.1

# Mapping of transmitter ids to WeeWX records
# Default for Vantage Pro2
mapping = th:1, th_indoor, baro, rain:1, wind:1, thw:1:appTemp, windchill:1, battery
mapping = th:1, th_indoor, baro, rain:1, wind:2, uv:2, solar:2, thw:1:appTemp, windchill:1, battery:1:outTemp:rain, battery:2:wind:uv

##############################################################################

Expand Down

0 comments on commit f455eb9

Please sign in to comment.