#!/usr/bin/env python3

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

import asyncio
import ssl
import websockets
import base64
import json
import argparse

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())
