Skip to content

Commit

Permalink
Fix weather station autodetect (#1254)
Browse files Browse the repository at this point in the history
* Fix port inconsistency for weatherstation

* `port` to `serial_port` consistently.

* * Remove serial_port from conf if passed.
  • Loading branch information
wtgee authored May 2, 2024
1 parent 6bdacc8 commit 4092f40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/panoptes/pocs/sensor/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class WeatherStation(PanBase):
"""

def __init__(self,
port: str = None,
serial_port: str = None,
name: str = 'Weather Station',
db_collection: str = 'weather',
*args, **kwargs):
"""Initialize the weather station.
Args:
port (str, optional): The dev port for the mount, usually the usb-serial converter.
serial_port (str, optional): The dev port for the mount, usually the usb-serial converter.
name (str): The user-friendly name for the weather station.
db_collection (str): Which collection (i.e. table) to store the values in, default 'weather'.
"""
Expand All @@ -29,12 +29,16 @@ def __init__(self,
conf.update(kwargs)
conf.pop('auto_detect', None)

self.port = port or conf.get('port', '/dev/ttyUSB0')
# Remove the conf port if passed one.
if serial_port is not None:
conf.pop('serial_port', None)

self.serial_port = serial_port or conf.get('serial_port', '/dev/ttyUSB0')
self.name = name
self.collection_name = db_collection

self.logger.debug(f'Setting up weather station connection for {name=} on {self.port}')
self.weather_station = CloudSensor(serial_port=self.port, **conf)
self.logger.debug(f'Setting up weather station connection for {name=} on {self.serial_port}')
self.weather_station = CloudSensor(serial_port=self.serial_port, **conf)

self.logger.debug(f'Weather station config: {self.weather_station.config}')
self.logger.info(f'{self.weather_station} initialized')
Expand Down
4 changes: 2 additions & 2 deletions src/panoptes/pocs/utils/service/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ async def startup():
if conf.get('auto_detect', False) is True:
ports = [p.device for p in get_comports()]
else:
ports = [conf['port']]
ports = [conf['serial_port']]

# Try to connect to the weather station.
for port in ports:
if 'ioptron' in port:
continue

conf['port'] = port
conf['serial_port'] = port
try:
weather_station = WeatherStation(**conf)
break
Expand Down

0 comments on commit 4092f40

Please sign in to comment.