Skip to content

Commit

Permalink
lower case message section
Browse files Browse the repository at this point in the history
- consistent with current standards
  • Loading branch information
bellrichm committed Mar 29, 2021
1 parent 836a497 commit 5106e71
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 94 deletions.
20 changes: 10 additions & 10 deletions bin/user/MQTTSubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
ciphers = None
# Configuration for the message callback.
# DEPRECATED - use [[[Message]]] under [[topics]]
# DEPRECATED - use [[[message]]] under [[topics]]
[[message_callback]]
# The format of the MQTT payload.
# Currently support: individual, json, keyword
Expand Down Expand Up @@ -224,7 +224,7 @@
max_queue = MAXSIZE
# Configuration information about the MQTT message format for this topic
[[[Message]]]
[[[message]]]
# The format of the MQTT payload.
# Currently support: individual, json, keyword.
# Must be specified.
Expand Down Expand Up @@ -677,9 +677,9 @@ def __init__(self, archive_topic, config, logger):
field_defaults['conversion_type'] = config.get('conversion_type', 'float')
field_defaults['conversion_error_to_none'] = to_bool(config.get('conversion_error_to_none', False))

default_message_dict = config.get('Message', configobj.ConfigObj())
default_message_dict = config.get('message', configobj.ConfigObj())
# if 'type' option is not set, this not 'topic'
# so, no default 'Message' configuration exists
# so, no default 'message' configuration exists
if default_message_dict.get('type', None) is None:
default_message_dict = configobj.ConfigObj({})

Expand Down Expand Up @@ -709,7 +709,7 @@ def __init__(self, archive_topic, config, logger):
callback_config_name = topic_dict.get('callback_config_name', topic_defaults['callback_config_name'])

# if 'type' option is set, this not a 'topic'
# it is actually a 'Message' configuration stanza
# it is actually a 'callback (message)' configuration stanza
# and it has already been retrieved into default_message_config
if topic == callback_config_name and topic_dict.get('type', None) is not None:
continue
Expand Down Expand Up @@ -761,7 +761,7 @@ def __init__(self, archive_topic, config, logger):
message_dict = configobj.ConfigObj({})
message_dict.merge(default_message_dict)

# if 'type' option is set, this a 'Message'
# if 'type' option is set, this a 'callback configuration (message)' section
# So merge the default message settings
if message_type is not None:
message_dict.merge(temp_message_dict)
Expand Down Expand Up @@ -862,7 +862,7 @@ def _configure_topic_options(self, config):
default['offset_format'] = config.get('offset_format', None)

default['max_queue'] = config.get('max_queue', MAXSIZE)
default['callback_config_name'] = config.get('callback_config_name', 'Message')
default['callback_config_name'] = config.get('callback_config_name', 'message')

return default

Expand Down Expand Up @@ -1232,13 +1232,13 @@ def __init__(self, config, logger, topic_manager):
if not topic_manager.subscribed_topics[topic][topic_manager.message_config_name]:
topic_manager.subscribed_topics[topic][topic_manager.message_config_name] = config.dict()
else:
self.logger.info("Message configuration found under [[MessageCallback]] and [[Topic]]. Ignoring [[MessageCallbwck]].")
self.logger.info("Message configuration found under [[MessageCallback]] and [[Topic]]. Ignoring [[MessageCallback]].")

if not topic_manager.subscribed_topics[topic][topic_manager.message_config_name]:
raise ValueError("%s topic is missing '[[[[Message]]]]' section" % topic)
raise ValueError("%s topic is missing '[[[[message]]]]' section" % topic)
message_type = topic_manager.subscribed_topics[topic][topic_manager.message_config_name].get('type', None)
if message_type is None:
raise ValueError("%s topic is missing '[[[[Message]]]] type=' section" % topic)
raise ValueError("%s topic is missing '[[[[message]]]] type=' section" % topic)
if message_type not in ['json', 'keyword', 'individual']:
raise ValueError("Invalid type configured: %s" % message_type)

Expand Down
40 changes: 20 additions & 20 deletions bin/user/tests/unit/test_MQTTSubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def test_configure_observation(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['observations'] = {}
config_dict['weewx']['observations'][name] = value
Expand All @@ -315,8 +315,8 @@ def test_missing_group(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand All @@ -337,8 +337,8 @@ def test_missing_unit_system(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand All @@ -361,8 +361,8 @@ def test_invalid_unit_system(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand All @@ -387,8 +387,8 @@ def test_configure_default_label(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand Down Expand Up @@ -416,8 +416,8 @@ def test_configure_default_format(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand Down Expand Up @@ -445,8 +445,8 @@ def test_configure_conversion(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand Down Expand Up @@ -481,8 +481,8 @@ def test_unit_system_us(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand Down Expand Up @@ -512,8 +512,8 @@ def test_unit_system_metric(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand Down Expand Up @@ -543,8 +543,8 @@ def test_unit_system_metricwx(self):
config_dict = {}
config_dict['topics'] = {}
config_dict['topics'][topic] = {}
config_dict['topics'][topic]['Message'] = {}
config_dict['topics'][topic]['Message']['type'] = 'json'
config_dict['topics'][topic]['message'] = {}
config_dict['topics'][topic]['message']['type'] = 'json'
config_dict['weewx'] = {}
config_dict['weewx']['units'] = {}
config_dict['weewx']['units'][unit] = {}
Expand Down
6 changes: 3 additions & 3 deletions bin/user/tests/unit/test_MessageCallbackProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_message_and_message_callback_set():
user.MQTTSubscribe.MessageCallbackProvider(config, mock_logger, mock_manager)

mock_logger.info.assert_called_once_with( \
"Message configuration found under [[MessageCallback]] and [[Topic]]. Ignoring [[MessageCallbwck]].")
"Message configuration found under [[MessageCallback]] and [[Topic]]. Ignoring [[MessageCallback]].")

def test_message_and_message_callback_not_set(self):
mock_logger = mock.Mock(spec=Logger)
Expand All @@ -84,7 +84,7 @@ def test_message_and_message_callback_not_set(self):
with self.assertRaises(ValueError) as error:
user.MQTTSubscribe.MessageCallbackProvider(None, mock_logger, mock_manager)

self.assertEqual(error.exception.args[0], "%s topic is missing '[[[[Message]]]]' section" % topic)
self.assertEqual(error.exception.args[0], "%s topic is missing '[[[[message]]]]' section" % topic)

def test_message_callback_configuration_defaults_not_set(self):
mock_logger = mock.Mock(spec=Logger)
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_message_configuration_missing_type(self):
with self.assertRaises(ValueError) as error:
user.MQTTSubscribe.MessageCallbackProvider(None, mock_logger, mock_manager)

self.assertEqual(error.exception.args[0], "%s topic is missing '[[[[Message]]]] type=' section" % topic)
self.assertEqual(error.exception.args[0], "%s topic is missing '[[[[message]]]] type=' section" % topic)

# missing message section? todo

Expand Down
Loading

0 comments on commit 5106e71

Please sign in to comment.