Import Utilities

src.utils.importutils.get_classes_in_module(module_name: str, package_name: str, concrete_only: bool) Dict[str, Type][source]

Dynamically imports and identifies Python classes in the specified module and package.

Parameters:
  • module_name (str) – The name of the python module (e.g. ‘sensor’) whose classes should be imported.

  • package_name (str) – The name of the python package containing the specified module (e.g. ‘src.beemon’).

  • concrete_only (bool) – If True, only concrete subclasses of the python class which matches the specified module name will be imported. For instance, if this flag is set to True then sensor.Sensor will be ignored during the dynamic import, but sensor.Audio and class:sensor.Video will not be ignored since they are concrete subclasses of sensor.Sensor.

Returns:

A dictionary of class names and class types.

Return type:

Dict[str, Type]

Notes

This method returns a dictionary of class types (NOT instance types). If you wish to use the object, you must instantiate the object by calling the class’s constructor yourself.

src.utils.importutils.parse_global_sensor_settings_from_config_file(beemon_config: Config, sensor_name: str | None = None, sensor_override: bool | None = True) Tuple[tzinfo, str, str, datetime, datetime, int, int, bool][source]

A helper method which parses sensor-specific settings from the beemon-config.ini file, while defaulting to the [global] settings specified in the beemon-config.ini. Additionally, this method allows for the Sensor’s settings to take precedence over the global settings if the sensor_override flag is set to True.

Notes

This method will only return the configuration file arguments which are intended to be overridden by individual sensors. For instance, although pytz_time_zone is an argument in the [global] section of the beemon-config.ini this method will not return it; as individual sensors should not have the ability to override this value. The same is true of root_upload_directory, which is ignored by this method for the same reason.

See also

The utility/helper method invoked by this method parse_global_config().

Parameters:
  • beemon_config (Config) – An instance of the Config class.

  • sensor_name (Optional[str]) – The name of the Sensor whose configuration file arguments should be parsed. If no sensor name is provided, this method will simply return the parsed [global] section of the beemon-config.ini configuration file. If a sensor name is provided and the sensor_override flag is set to True then this method will override any settings specified under the [global] section, with the settings specified under the sensor’s section in the beemon-config.ini file. If the sensor_override flag is set to False then this method will simply return the parsed [global] section of the beemon-config.ini.

  • sensor_override (Optional[bool]) – Specifies if attributes declared in the beemon-config.ini file’s [global] section should be overridden by the concrete sensor subclass’s section in the same beemon-config.ini file. This value is True by default, indicating that the sensor’s configuration settings should take precedence over the global configuration. Please note that if the sensor_name is not provided, then this parameter will be set to False automatically, as there is no way to override global settings for an unspecified sensor.

Returns:

  • pytz_time_zone (:class:`datetime.tzinfo`): The pytz timezone in which the RPI is based.

  • root_upload_directory (str): The root directory on the remote machine to which data should be uploaded to.

  • sensor_local_output_directory (str): The local directory on the Pi to which recorded data should be written to prior to uploading. By default this value is: /home/bee/bee_tmp.

  • capture_window_start_time (datetime): A tz-aware datetime.datetime object which specifies when the first recording for the day should occur for the provided sensor_name. Note that this datetime will be tz-aware in accordance with the timezone/locale specified by the OS of the RPI itself (e.g. that which is given by the command: sudo raspi-config).

  • capture_window_end_time (datetime.datetime): A tz-aware datetime.datetime object which specifies when the last recording for the day should occur for the provided sensor_name. Note that this datetime will be tz-aware in accordance with the timezone/locale specified by the OS of the RPI itself (e.g. that which is given by the command: sudo raspi-config).

  • sensor_capture_duration_seconds (int): The number of seconds applicable sensors are to record for. For sensors which read instantaneously, this variable should have no discernible effect. For sensors which record in a loop (e.g. a video camera) this variable dictates how long the sensor is to consecutively record for.

  • sensor_capture_interval_seconds (int): The number of seconds which will be permitted to elapse before the next recording. Please note that it does not make sense for the sensor_capture_duration_seconds to exceed the sensor_capture_interval_seconds. Such a configuration (if specified) will be parsed without error, but downstream logic will raise an exception.

  • sensor_auto_start (bool): A boolean value indicating if the sensor should start recording automatically, or if it should wait to receive a manual start command via the bmon client.

Return type:

Tuple[str, str, str, datetime, datetime, int, int, bool]

Raises:

AttributeError – Raises an AttributeError in the event that the sensor is not formally declared in the beemon-config.ini.