Classes and data structures

Types

class slmon.models.BatteryModel(**data)

Battery overview.

class slmon.models.OpenDataModel(**data)

Represents the Open JSON dataset.

Exceptions

class slmon.exceptions.SLMonException

Base exception raised by the various parts of the application

class slmon.exceptions.WriterException

Raised by writer plugins.

class slmon.exceptions.SolarLogError

Raised when a problem with the connection to the data logger occurs.

Classes

class slmon.solarlogclient.SolarLogClient(host, login, username=None, password=None, dumper=None)

Represents the Solar-Log™ device. Provides a abstraction of the device and provides session handling.

Parameters
  • username (Optional[str]) – The username to log in (e.g. user)

  • password (Optional[str]) – The password to log in

  • host (str) – The host to connect to

  • login (bool) – Whether to log in and try to maintain a session.

  • dumper (Optional[Dumper]) – Optional dumper that, when set, dumps the retrieved data as soon as possible.

do_logcheck()

Checks the login and access state. The data is stored internally.

Raises

SolarLogError – If querying failed or the data is not parseable.

Return type

None

do_login()

Performs the login action. Updates the internal _logged_in value and returns whether it was successful.

Return type

bool

Returns

Whether it was successful.

dump(filename, data)

If the dumper is available, hands of the data to be dumped.

Parameters
  • filename (str) – The name of the file to dump into. The dumper adds a timestamp and the json extension on it own.

  • data (str) – The data to dump.

Return type

None

get_lcd()

Queries for the current set of LCD data and returns the result as a dict. This function works without valid login.

Return type

Dict

get_open_json()

Requests the “Open JSON” output. This does not require a login. The keys are converted to integers on the fly.

Return type

Dict

get_revision()

Queries the device for the current revision number.

Return type

int

getjp(data)

Low-level function to access the getjp endpoint of the Solar-Log™ device. If the JSON response contains the words ACCESS DENIED, then the logout handler is triggered.

Parameters

data (str) – The query string. If logged in, the token will automatically be prepended.

Return type

Response

Returns

The response object.

handle_logout()

Performs the neccessary steps to return to a clean, not logged-in state. This is used when the client detects that the server does not consider its session valid anymore.

Return type

None

init_data()

Initializes internal data structures, should be called after a reconnect.

Return type

None

init_session()

Initializes the requests session

Return type

None

property logged_in

Returns whether the client thinks that its session is valid. This value is updated on querying the data logger.

Return type

bool

property login

Returns whether the client performs a login if it detects that its session has ended.

Return type

bool

set_login(login)

Controls whether the client tries to log in before the next request if it detects that it is not logged in. This can be set to False before accessing the Solar-Log™ with a webbrowser as it does not allow more than one active session and the client would kick the user out of the session each time it is called.

Return type

None

property sl_revision

Returns the Solar-Log™ revision. If the revision has not been queried before, performs a query.

Raises

SolarLogError – If the query for the revision failed.

Return type

int

Interfaces

class slmon.datasink.DataSink

Interface for receiving parsed data from the Mapper. The mapper calls the functions, starting with on_begin() at the beginning of mapping, ending with on_end() after the mapper has finished.

on_battery(data)

Called when the battery overview has been found.

Return type

None

on_begin(timestamp=None)

Called at the beginning before sending other data. If the mapper found a timestamp in the data, it is passed as argument.

Return type

None

on_complete()

Called at the end of mapping. This can be used to commit transactions or do calculations on the data received.

Return type

None

on_inventory(info, data)

Called when inventory information is encountered.

Parameters
  • info (str) – The type of information, such as serials for serial numbers.

  • data (Dict) – The data depending on the info.

Return type

None

on_open_data(data)

Called when data from the Open JSON API has been found.

Return type

None

on_plain(name, datatype, value)

Called when a known free-standing value was found.

Name

Name of the value according to current knowledge.

Parameters
  • datatype (str) – Type of the data, one of: int, str, dict, list

  • value (Union[int, str, Dict, List]) – The value.

Return type

None

on_unknown(datatype, path, value)

Called when an unknown data point is found.

Parameters
  • datatype (str) – The type of data, one of: int, str, list, dict.

  • path (List[int]) – The path of the data. The Open JSON timestamp {801:{170:{100}}} would be encoded as [801, 170, 100] in this structure.

  • value (Union[int, str, Dict, List]) – The data value.

Return type

None

Outputs

class slmon.dumper.Dumper(base_dir)

Dumps the received string to filesystem. The timestamp can be set using fix_ts() to allow for multiple files to be written with the same timestamp encoded into the file name.

To avoid stressing the filesystem, one file per hour is created. This ensures that the amount of files in a directory is somewhat limited. Each file written has the unix timestamp encoded into the filename, too.

Parameters

base_dir (str) – Base directory, everything will be dumped below this path. An attempt to create it is made if it does not exist.

dump(filename, data, ext='.json')

Dumps a string of data to a file. The current timestamp (see fix_ts()) is appended, following by the extension. The file is written in an atomic manner.

Parameters
  • filename (str) – The base filename to use for dumping. Timestamp and extension are appended automatically.

  • data (str) – The data to dump.

  • ext (str) – Filename extension, appended after the timestamp.

Return type

None

fix_ts()

Updates the internal timestamp to the current UTC time.

Return type

None

Settings

slmon.settings.SLMonSettings