sensors: Add sensor name argument

This commit is contained in:
polyfloyd 2025-05-05 22:41:28 +02:00
parent 581665fa95
commit 9b64fa14fb

18
main.py
View file

@ -72,11 +72,11 @@ async def state(ctx):
# !co2 # !co2
@HobbyBot.command(description="co2 levels") @HobbyBot.command(description="co2 levels")
async def co2(ctx): async def co2(ctx, where='hoofdruimte'):
async with ctx.typing(): async with ctx.typing():
try: try:
msg = await mqtt_get_one("bitlair/climate/hoofdruimte/co2_ppm") msg = await mqtt_get_one(f"bitlair/climate/{where}/co2_ppm")
await ctx.send(f"Hoofdruimte: {msg.payload.decode('ascii')} ppm\n") await ctx.send(f"{where}: {msg.payload.decode('ascii')} ppm\n")
except Exception as err: except Exception as err:
await ctx.send("Meh, stuk") await ctx.send("Meh, stuk")
raise err raise err
@ -84,11 +84,11 @@ async def co2(ctx):
# !temp # !temp
@HobbyBot.command(description="Temperature") @HobbyBot.command(description="Temperature")
async def temp(ctx): async def temp(ctx, where="hoofdruimte"):
async with ctx.typing(): async with ctx.typing():
try: try:
msg = await mqtt_get_one("bitlair/climate/hoofdruimte/temperature_c") msg = await mqtt_get_one(f"bitlair/climate/{where}/temperature_c")
await ctx.send(f"Hoofdruimte: {msg.payload.decode('ascii')} °C\n") await ctx.send(f"{where}: {msg.payload.decode('ascii')} °C\n")
except Exception as err: except Exception as err:
await ctx.send("Meh, stuk") await ctx.send("Meh, stuk")
raise err raise err
@ -96,11 +96,11 @@ async def temp(ctx):
# !humid # !humid
@HobbyBot.command(description="Humidity") @HobbyBot.command(description="Humidity")
async def humid(ctx): async def humid(ctx, where="hoofdruimte"):
async with ctx.typing(): async with ctx.typing():
try: try:
msg = await mqtt_get_one("bitlair/climate/hoofdruimte/humidity_pct") msg = await mqtt_get_one(f"bitlair/climate/{where}/humidity_pct")
await ctx.send(f"Hoofdruimte: {msg.payload.decode('ascii')} pct\n") await ctx.send(f"{where}: {msg.payload.decode('ascii')} pct\n")
except Exception as err: except Exception as err:
await ctx.send("Meh, stuk") await ctx.send("Meh, stuk")
raise err raise err