#!/usr/bin/env python3

# Example of streaming sensor values from openbmc using the /subscribe api
# requires websockets package to be installed

import argparse
import asyncio
import base64
import json
import ssl

import websockets

parser = argparse.ArgumentParser()
parser.add_argument("--host", help="Host to connect to", required=True)
parser.add_argument(
    "--username", help="Username to connect with", default="root"
)
parser.add_argument("--password", help="Password to use", default="0penBmc")
parser.add_argument(
    "--ssl", default=True, action=argparse.BooleanOptionalAction
)

args = parser.parse_args()

sensor_type_map = {
    "voltage": "Volts",
    "power": "Watts",
    "fan": "RPM",
    "fan_tach": "RPM",
    "temperature": "Degrees C",
    "altitude": "Meters",
    "current": "Amps",
    "energy": "Joules",
    "cfm": "CFM",
}


async def hello():
    protocol = "ws"
    if args.ssl:
        protocol += "s"
    uri = "{}://{}/subscribe".format(protocol, args.host)
    ssl_context = ssl.SSLContext()
    authbytes = "{}:{}".format(args.username, args.password).encode("ascii")
    auth = "Basic {}".format(base64.b64encode(authbytes).decode("ascii"))
    headers = {"Authorization": auth}
    async with (
        websockets.connect(uri, ssl=ssl_context, extra_headers=headers)
        if args.ssl
        else websockets.connect(uri, extra_headers=headers)
    ) as websocket:
        request = json.dumps(
            {
                "paths": ["/xyz/openbmc_project/sensors"],
                "interfaces": ["xyz.openbmc_project.Sensor.Value"],
            }
        )
        await websocket.send(request)

        while True:
            payload = await websocket.recv()
            j = json.loads(payload)
            path = j.get("path", "unknown/unknown")
            name = path.split("/")[-1]
            sensor_type = path.split("/")[-2]
            units = sensor_type_map.get(sensor_type, "")
            properties = j.get("properties", [])
            value = properties.get("Value", None)
            if value is None:
                continue
            print(f"{name:<20} {value:4.02f} {units}")


asyncio.get_event_loop().run_until_complete(hello())
