Skip to main content

An unofficial Python library to interface with your USMS account and smart meters.

Project description

USMS

An unofficial Python library to interface with your USMS account and smart meters.

Getting Started

Installation

python -m pip install usms

Quickstart

python -m usms --help
usage: __main__.py [-h] [-l LOG] -u USERNAME -p PASSWORD [-m METER] [--unit] [--consumption] [--credit]

options:
  -h, --help            show this help message and exit
  -l LOG, --log LOG
  -u USERNAME, --username USERNAME
  -p PASSWORD, --password PASSWORD
  -m METER, --meter METER
  --unit
  --consumption
  --credit

[!NOTE] The username parameter is the login ID that you use to log-in on the USMS website/app, i.e. your IC Number.

As an example, you can use the following command to get the current remaining unit:

python -m usms -u <ic_number> -p <password> -m <meter> --unit

You can also use environment variables for the login information:

export USMS_USERNAME="<ic_number>"
export USMS_PASSWORD="<password>"
python -m usms -m <meter> --unit

Or:

USMS_USERNAME="<ic_number>" USMS_PASSWORD="<password>" python -m usms -m <meter> --unit

Usage

import httpx

from usms import initialize_usms_account

username = "01001234" # your ic number
password = "hunter1"

# initialize the account
account = initialize_usms_account(
    username=username,
    password=password,
    client=httpx.Client(),  # or httpx.AsyncClient(), optional
)

# print out the account information
print(account.name)

# print out info on all meters under the account
for meter in account.meters:
    print(meter.no)
    print(meter.type)
    print(meter.address)
    print(meter.remaining_unit)
    print(meter.remaining_credit)
    print(meter.unit)

# get the number of the second meter
meter_no = account.meters[1].no

# to get info from a specific meter
meter = account.get_meter(meter_no)

# get today's consumptions
print(meter.get_last_n_days_hourly_consumptions(n=0))

# getting daily breakdown of last month's comsumptions
daily_consumptions = meter.get_previous_n_month_consumptions(n=1)
print(daily_consumptions)
# get last month's total cost based on total consumption
print(meter.calculate_total_cost(daily_consumptions))

To-Do

  • Add more test coverage
  • Support for water meter
  • Support for commercial/corporate accounts

Contributing

Prerequisites

  1. Generate an SSH key and add the SSH key to your GitHub account.

  2. Configure SSH to automatically load your SSH keys:

    cat << EOF >> ~/.ssh/config
    
    Host *
      AddKeysToAgent yes
      IgnoreUnknown UseKeychain
      UseKeychain yes
      ForwardAgent yes
    EOF
    
  3. Install Docker Desktop.

  4. Install VS Code and VS Code's Dev Containers extension. Alternatively, install PyCharm.

  5. Optional: install a Nerd Font such as FiraCode Nerd Font and configure VS Code or PyCharm to use it.

Development Environments

The following development environments are supported:

  1. ⭐️ GitHub Codespaces: click on Open in GitHub Codespaces to start developing in your browser.

  2. ⭐️ VS Code Dev Container (with container volume): click on Open in Dev Containers to clone this repository in a container volume and create a Dev Container with VS Code.

  3. ⭐️ uv: clone this repository and run the following from root of the repository:

    # Create and install a virtual environment
    uv sync --python 3.10 --all-extras
    
    # Activate the virtual environment
    source .venv/bin/activate
    
    # Install the pre-commit hooks
    pre-commit install --install-hooks
    
  4. VS Code Dev Container: clone this repository, open it with VS Code, and run Ctrl/⌘ + + PDev Containers: Reopen in Container.

  5. PyCharm Dev Container: clone this repository, open it with PyCharm, create a Dev Container with Mount Sources, and configure an existing Python interpreter at /opt/venv/bin/python.

Developing

  • This project follows the Conventional Commits standard to automate Semantic Versioning and Keep A Changelog with Commitizen.
  • Run poe from within the development environment to print a list of Poe the Poet tasks available to run on this project.
  • Run uv add {package} from within the development environment to install a run time dependency and add it to pyproject.toml and uv.lock. Add --dev to install a development dependency.
  • Run uv sync --upgrade from within the development environment to upgrade all dependencies to the latest versions allowed by pyproject.toml. Add --only-dev to upgrade the development dependencies only.
  • Run cz bump to bump the package's version, update the CHANGELOG.md, and create a git tag. Then push the changes and the git tag with git push origin main --tags.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgments

Project Template

This project was built using the superlinear-ai/substrate template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usms-0.9.0.tar.gz (102.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usms-0.9.0-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file usms-0.9.0.tar.gz.

File metadata

  • Download URL: usms-0.9.0.tar.gz
  • Upload date:
  • Size: 102.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.8

File hashes

Hashes for usms-0.9.0.tar.gz
Algorithm Hash digest
SHA256 918a88c229d7c940c0f633a0bf1c0551382799fd9fc045b7b3b7eb81af37d845
MD5 24a3a986cb0df86562bf945c508dfba5
BLAKE2b-256 70e1538f3b0c8df5aba6fcf2a5747820c341252143c2278eb4c66a6e5f22d213

See more details on using hashes here.

File details

Details for the file usms-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: usms-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.8

File hashes

Hashes for usms-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e49610e655abfcc82faca128d77d2f9509e69066802d55555c9bc5ac154fef58
MD5 37d34ff5d172e63f0d7295b6c4af58aa
BLAKE2b-256 4a0386bfca0b7992507f1d0b5ac69250c284e98fa5b5df5f2747c72911265a27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page