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
Truethensensor.Sensorwill be ignored during the dynamic import, butsensor.Audioand class:sensor.Video will not be ignored since they are concrete subclasses ofsensor.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[str, datetime, datetime, int, int, bool][source]
A helper method which parses sensor-specific settings from the
beemon-config.inifile, while defaulting to the[global]settings specified in thebeemon-config.ini. Additionally, this method allows for the Sensor’s settings to take precedence over the global settings if thesensor_overrideflag is set toTrue.Notes
This method will only return the configuration file arguments which are intended to be overridden by individual sensors. For instance, although
pytz_time_zoneis an argument in the[global]section of thebeemon-config.inithis method will not return it; as individual sensors should not have the ability to override this value. The same is true ofroot_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:
sensor_name (Optional[str]) – The name of the
Sensorwhose configuration file arguments should be parsed. If no sensor name is provided, this method will simply return the parsed[global]section of thebeemon-config.iniconfiguration file. If a sensor name is provided and thesensor_overrideflag is set toTruethen this method will override any settings specified under the[global]section, with the settings specified under the sensor’s section in thebeemon-config.inifile. If thesensor_overrideflag is set toFalsethen this method will simply return the parsed[global]section of thebeemon-config.ini.sensor_override (Optional[bool]) – Specifies if attributes declared in the
beemon-config.inifile’s[global]section should be overridden by the concrete sensor subclass’s section in the samebeemon-config.inifile. This value isTrueby default, indicating that the sensor’s configuration settings should take precedence over the global configuration. Please note that if thesensor_nameis not provided, then this parameter will be set toFalseautomatically, as there is no way to override global settings for an unspecified sensor.
- Returns:
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-awaredatetime.datetimeobject which specifies when the first recording for the day should occur for the providedsensor_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-awaredatetime.datetimeobject which specifies when the last recording for the day should occur for the providedsensor_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_secondsto exceed thesensor_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
startcommand via thebmonclient.
- Return type:
- Raises:
AttributeError – Raises an
AttributeErrorin the event that the sensor is not formally declared in thebeemon-config.ini.