battery_handyman package

Submodules

battery_handyman.battery_handyman_class module

It carries out the tasks on the battery servicing

Now it only sends customizable HTTP requests when the battery percentage reaches user-defined limits

class battery_handyman.battery_handyman_class.BatteryHandyman(battery_limit_config: Optional[battery_handyman.battery_handyman_class.ConfigSectionNamespace] = None, check_config: Optional[battery_handyman.battery_handyman_class.ConfigSectionNamespace] = None, remote_request_config: Optional[battery_handyman.battery_handyman_class.ConfigSectionNamespace] = None)

Bases: object

Central class

YAML_TAG = '!BatteryHandyman'
property battery_limit_charged

A threshold. A battery is considered as charged if its percentage is greater than the threshold

property battery_limit_low

A threshold. A battery is considered as low enough to charge if its percentage is less than the threshold

property check_interval

A time interval between checks in seconds

extract_request_data(battery_info: battery_handyman.util.BatteryInfo) → Dict[str, Any]

Transforms battery_info into the dictionary of the data requited by the request line template

classmethod from_configuration_file(configuration_filepath: str) → battery_handyman.battery_handyman_class.BatteryHandyman

Creates an instance using the file path pointing at the configuration file

static from_yaml(loader: yaml.loader.SafeLoader, node: Any) → battery_handyman.battery_handyman_class.BatteryHandyman

A YAML loading function

See also https://stackoverflow.com/a/49458752

init_from_config_dict_mapping(config_dict_mapping: Dict[str, Dict[str, Any]]) → None

Initializes the instance using a configuration dictionary

map_request_data_inplace(request_data: Dict[str, Any]) → None

Maps the values extracted from battery_info to the specified in the configuration

perform_check() → None

Obtains battery_info, pass it to send_request and schedule the next check

property remote_address

The address of the remote device that controls the charging of this device

property request_data_mapping

A mapping for the values prepared for request_template

property request_method

A HTTP method of the requests

property request_template

A URL path template with named placeholders

schedule_new_check(initial: bool = False) → None

Only adds additional entry in the scheduler

send_request(battery_info: battery_handyman.util.BatteryInfo) → None

Runs the whole pipeline from processing battery_info to HTTP response handling

start(blocking: bool = True) → None

Runs the check cycle

stop() → None

Stops the check cycle

to_config_dict_mapping() → Dict[str, Dict[str, Any]]

Creates a configuration dictionary from the instance

to_configuration_file(configuration_filepath: str) → None

Creates the configuration file under the provided file path

static to_yaml(dumper: yaml.dumper.SafeDumper, data: battery_handyman.battery_handyman_class.BatteryHandyman) → yaml.nodes.MappingNode

A YAML dumping function

class battery_handyman.battery_handyman_class.ConfigSectionNamespace(**kwargs)

Bases: argparse.Namespace

A representation of a configuration section

Defined for the type-checking purposes

battery_handyman.battery_handyman_class.common_only_battery_limit_property_setter_routine(target_property: Callable) → Callable

Adds checking of the provided limit value

battery_handyman.battery_handyman_class.common_property_setter_routine(target_property: Callable) → Callable

Add logging of the target property and the provided value

battery_handyman.cli module

The setup of the CLI arguments parsing

battery_handyman.cli.setup_parser() → argparse.ArgumentParser

Return the parser of the CLI arguments

battery_handyman.constants module

Package-level constants

battery_handyman.main module

Top-level commands

battery_handyman.main.main(args: List[str], path_to_dir_with_main_module: str = 'battery_handyman', testing: bool = False) → None

The entrypoint of the application

With testing == False this function can not be covered

battery_handyman.util module

Auxiliary package-level definitions

class battery_handyman.util.BatteryInfo

Bases: tuple

A package-level representation of a battery state

property is_charging

Alias for field number 0

property left_in_percents

Alias for field number 1

exception battery_handyman.util.DoNotToogleChargingException(*args, **kwargs)

Bases: Exception

Signals that the charging process must be unchangedCharging must not to be toogled

battery_handyman.util.get_battery_info() → battery_handyman.util.BatteryInfo

Return a namespace with the is_charging and left_in_percents key-values

battery_handyman.util.parse_request_data_key_list(request_template: str) → List[str]

Extract the names of the placeholders in the request line template

Module contents

The top-level members of the module