mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +01:00
add info.py cog
This commit is contained in:
parent
551e858dcd
commit
6ca516971d
1 changed files with 23 additions and 14 deletions
37
cogs/info.py
37
cogs/info.py
|
@ -1,6 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
@ -14,7 +15,8 @@ try:
|
||||||
import fanshim
|
import fanshim
|
||||||
import apa102
|
import apa102
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
except ImportError:
|
except ImportError as e:
|
||||||
|
print("Raspberry Pi libraries not found.", e, file=sys.stderr)
|
||||||
fanshim = GPIO = apa102 = None
|
fanshim = GPIO = apa102 = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +29,8 @@ class InfoCog(commands.Cog):
|
||||||
"NETWORK": "\N{satellite antenna}",
|
"NETWORK": "\N{satellite antenna}",
|
||||||
"SENSORS": "\N{thermometer}",
|
"SENSORS": "\N{thermometer}",
|
||||||
"UPTIME": "\N{alarm clock}",
|
"UPTIME": "\N{alarm clock}",
|
||||||
|
"ON": "\N{large green circle}",
|
||||||
|
"OFF": "\N{large red circle}",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -120,41 +124,46 @@ class InfoCog(commands.Cog):
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=f"{self.EMOJIS['SENSORS']} Temperature (coretemp)",
|
name=f"{self.EMOJIS['SENSORS']} Temperature (coretemp)",
|
||||||
value="\n".join(f"{s.label}: {s.current:.2f}°C" for s in temperature["coretemp"]),
|
value="\n".join(f"{s.label}: {s.current:.2f}°C" for s in temperature["coretemp"]),
|
||||||
inline=False,
|
inline=True,
|
||||||
)
|
)
|
||||||
elif "acpitz" in temperature:
|
elif "acpitz" in temperature:
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=f"{self.EMOJIS['SENSORS']} Temperature (acpitz)",
|
name=f"{self.EMOJIS['SENSORS']} Temperature (acpitz)",
|
||||||
value="\n".join(f"{s.label}: {s.current:.2f}°C" for s in temperature["acpitz"]),
|
value="\n".join(f"{s.label}: {s.current:.2f}°C" for s in temperature["acpitz"]),
|
||||||
inline=False,
|
inline=True,
|
||||||
)
|
)
|
||||||
elif "cpu_thermal" in temperature:
|
elif "cpu_thermal" in temperature:
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=f"{self.EMOJIS['SENSORS']} Temperature (cpu_thermal)",
|
name=f"{self.EMOJIS['SENSORS']} Temperature (cpu_thermal)",
|
||||||
value="\n".join(f"{s.label}: {s.current:.2f}°C" for s in temperature["cpu_thermal"]),
|
value="\n".join(f"{s.label}: {s.current:.2f}°C" for s in temperature["cpu_thermal"]),
|
||||||
inline=False,
|
inline=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if fans:
|
if fans:
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=f"{self.EMOJIS['SENSORS']} Fans",
|
name=f"{self.EMOJIS['SENSORS']} Fans",
|
||||||
value="\n".join(f"{s.label}: {s.current:.2f} RPM" for s in fans),
|
value="\n".join(f"{s.label}: {s.current:.2f} RPM" for s in fans),
|
||||||
inline=False,
|
inline=True,
|
||||||
)
|
)
|
||||||
if fanshim:
|
if fanshim:
|
||||||
# PiMoroni's fanshim by default uses pin 18 for control
|
# PiMoroni's fanshim by default uses pin 18 for control
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(18, GPIO.IN)
|
||||||
fan_active = bool(GPIO.input(18))
|
fan_active = bool(GPIO.input(18))
|
||||||
LED = apa102.APA102(1, 15, 14, None)
|
# LED = apa102.APA102(1, 15, 14, None)
|
||||||
# Get LED colour as a tuple of (r, g, b)
|
# Get LED colour as a tuple of (r, g, b)
|
||||||
LED_colour = LED.get_pixel_colour(0)
|
# LED_colour = LED.get_pixel_colour(0)
|
||||||
# Convert to hex
|
# Convert to hex
|
||||||
LED_colour = "%02x%02x%02x" % LED_colour
|
# LED_colour = "%02x%02x%02x" % LED_colour
|
||||||
|
LED_colour = "unknown"
|
||||||
|
fan_state = f"{self.EMOJIS['OFF']} Inactive"
|
||||||
if fan_active:
|
if fan_active:
|
||||||
embed.add_field(
|
fan_state = f"{self.EMOJIS['ON']} Active"
|
||||||
name=f"{self.EMOJIS['SENSORS']} Fan",
|
embed.add_field(
|
||||||
value=f"{self.EMOJIS['ON']} Active (LED: #{LED_colour})",
|
name=f"{self.EMOJIS['SENSORS']} Fan",
|
||||||
inline=False,
|
value=f"{fan_state} (LED: #{LED_colour})",
|
||||||
)
|
inline=True,
|
||||||
|
)
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=f"{self.EMOJIS['RAM']} RAM",
|
name=f"{self.EMOJIS['RAM']} RAM",
|
||||||
|
@ -184,7 +193,7 @@ class InfoCog(commands.Cog):
|
||||||
name=f"{self.EMOJIS['NETWORK']} Network",
|
name=f"{self.EMOJIS['NETWORK']} Network",
|
||||||
value=f"**Sent:** {humanize.naturalsize(network.bytes_sent, binary=binary)}\n"
|
value=f"**Sent:** {humanize.naturalsize(network.bytes_sent, binary=binary)}\n"
|
||||||
f"**Received:** {humanize.naturalsize(network.bytes_recv, binary=binary)}",
|
f"**Received:** {humanize.naturalsize(network.bytes_recv, binary=binary)}",
|
||||||
inline=False,
|
inline=True,
|
||||||
)
|
)
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name=f"{self.EMOJIS['UPTIME']} Uptime",
|
name=f"{self.EMOJIS['UPTIME']} Uptime",
|
||||||
|
|
Loading…
Reference in a new issue