Skip to content

Commit

Permalink
Stash
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Nov 11, 2023
1 parent 6a02a3b commit 008b16f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 46 deletions.
84 changes: 38 additions & 46 deletions wideboy/scenes/default/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@

from typing import Any


def number_to_color(
number: float, ranges=[0.3, 0.6, 1.0], brightness=255, invert=False
) -> Color:
color_low = Color(brightness, 0, 0, 255)
color_mid = Color(brightness, brightness, 0, 255)
color_high = Color(0, brightness, 0, 255)
color_default = Color(0, 0, 0, 255)
if invert:
color_low, color_high = color_high, color_low
if number < ranges[0]:
return color_low
elif ranges[0] <= number < ranges[1]:
return color_mid
elif ranges[1] <= number <= ranges[2]:
return color_high
else:
return Color(0, 0, 0, 255)


# GENERAL


class GridTileStepsLouis(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_DIRECTIONS_WALK
icon_color_fg = Color(255, 0, 255, 255)

def process(self, state):
value = state.get("sensor.steps_louis", 0)
Expand All @@ -21,7 +40,6 @@ def process(self, state):

class GridTileVPN(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_LOCK
icon_color_fg = Color(255, 0, 0, 255)

def process(self, state):
value = state.get("sensor.privacy_ip_info", None)
Expand All @@ -31,7 +49,6 @@ def process(self, state):

class GridTileTransmission(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_VPN_LOCK
icon_color_fg = Color(255, 255, 255, 255)

def process(self, state):
value = state.get("sensor.transmission_down_speed", 0)
Expand All @@ -41,7 +58,6 @@ def process(self, state):

class GridTileDS920Plus(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_DNS
icon_color_fg = Color(255, 255, 0, 255)

def process(self, state):
value = state.get("sensor.ds920plus_volume_used", 0)
Expand All @@ -51,31 +67,28 @@ def process(self, state):

class GridTileSpeedtestDownload(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_DOWNLOAD
icon_color_fg = Color(0, 255, 0, 255)

def process(self, state):
self.visible = True
value = state.get("sensor.speedtest_download_average", 0)
value = float(state.get("sensor.speedtest_download_average", 0))
self.label = f"{value:.0f}Mbs"
self.label_color_bg = Color(0, 192, 0, 255)
self.progress = float(value) / 900
self.label_color_bg = number_to_color(value / 900, brightness=128)
self.progress = value / 900


class GridTileSpeedtestUpload(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_UPLOAD
icon_color_fg = Color(255, 0, 0, 255)

def process(self, state):
self.visible = True
value = state.get("sensor.speedtest_upload_average", 0)
value = float(state.get("sensor.speedtest_upload_average", 0))
self.label = f"{value:.0f}Mbs"
self.label_color_bg = Color(192, 0, 0, 255)
self.progress = float(value) / 900
self.label_color_bg = number_to_color(value / 900, brightness=128)
self.progress = value / 900


class GridTileSpeedtestPing(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_WIFI
icon_color_fg = Color(0, 0, 255, 255)

def process(self, state):
self.visible = True
Expand All @@ -85,7 +98,6 @@ def process(self, state):

class GridTileBinCollection(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_DELETE
icon_color_fg = Color(192, 192, 192, 255)

def process(self, state):
value = state.get("calendar.bin_collection")
Expand All @@ -95,7 +107,6 @@ def process(self, state):

class GridTileBackDoor(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_DOOR
icon_color_fg = Color(255, 64, 64, 255)
label = "Back"

def process(self, state):
Expand All @@ -106,7 +117,6 @@ def process(self, state):

class GridTileFrontDoor(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_DOOR
icon_color_fg = Color(255, 64, 64, 255)
label = "Front"

def process(self, state):
Expand All @@ -117,7 +127,6 @@ def process(self, state):

class GridTileHouseManual(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_TOGGLE_ON
icon_color_fg = Color(255, 0, 0, 255)
label = "MANUAL"

def process(self, state):
Expand All @@ -126,7 +135,6 @@ def process(self, state):

class GridTileSwitchLoungeFans(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_AC_UNIT
icon_color_fg = Color(196, 196, 255, 255)
label = "ON"

def process(self, state):
Expand All @@ -141,71 +149,58 @@ class GridTileElectricityCurrentDemand(HomeAssistantEntityGridTile):
icon_color_fg = Color(192, 192, 192, 255)

def process(self, state):
value = state.get("sensor.octopus_energy_electricity_current_demand", 0)
value = float(state.get("sensor.octopus_energy_electricity_current_demand", 0))
self.visible = value > 0
self.label = f"{value:.0f}w"
self.icon_color_fg = (
Color(255, 64, 64, 255) if value > 500 else Color(64, 255, 64, 255)
self.label_color_bg = number_to_color(
value, [300, 600, 900], brightness=128, invert=True
)


class GridTileElectricityCurrentRate(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_SYMBOL_AT
icon_color_fg = Color(192, 192, 192, 255)

def process(self, state: dict[str, Any]):
value = state.get("sensor.octopus_energy_electricity_current_rate", 0)
value = float(state.get("sensor.octopus_energy_electricity_current_rate", 0))
self.visible = value > 0
self.label = f"£{value:.2f}"
self.icon_color_fg = (
Color(255, 64, 64, 255) if value > 0.30 else Color(64, 255, 64, 255)
self.label_color_bg = number_to_color(
value, [0.10, 0.30, 1.0], brightness=128, invert=True
)


class GridTileElectricityHourlyRate(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_CURRENCY_DOLLAR
icon_color_fg = Color(255, 64, 64, 255)

def process(self, state):
value = state.get("sensor.electricity_hourly_rate", 0)
value = float(state.get("sensor.electricity_hourly_rate", 0))
self.visible = value > 0
self.label = f"£{value:.2f}"
self.icon_color_fg = (
Color(255, 64, 64, 255) if value > 0.50 else Color(64, 255, 64, 255)
)


class GridTileElectricityCurrentAccumulativeCost(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_SCHEDULE
icon_color_fg = Color(255, 64, 64, 255)

def process(self, state):
value = state.get(
"sensor.octopus_energy_electricity_current_accumulative_cost", 0
value = float(
state.get("sensor.octopus_energy_electricity_current_accumulative_cost", 0)
)
self.visible = value > 0
self.label = f"£{value:.2f}"
self.icon_color_fg = (
Color(255, 64, 64, 255) if value > 2.50 else Color(64, 255, 64, 255)
)


# GRID: BATTERY


class GridTileBatteryLevel(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_BATTERY
icon_color_fg = Color(192, 192, 192, 255)

def process(self, state):
value = state.get("sensor.delta_2_max_downstairs_battery_level", 0)
value = float(state.get("sensor.delta_2_max_downstairs_battery_level", 0))
self.visible = value > 0
self.label = f"{value:.0f}%"
self.icon_color_fg = (
Color(255, 64, 64, 255) if value < 30 else Color(64, 255, 64, 255)
)
self.label_color_bg = Color(192, 0, 0, 255)
self.progress = float(value) / 100
self.label_color_bg = number_to_color(value / 100, brightness=128)
self.progress = value / 100


class GridTileBatteryCycles(HomeAssistantEntityGridTile):
Expand All @@ -220,7 +215,6 @@ def process(self, state):

class GridTileBatteryDischargeRemainingTime(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_HOURGLASS
icon_color_fg = Color(255, 64, 64, 255)

def process(self, state):
value = state.get("sensor.delta_2_max_downstairs_discharge_remaining_time", 0)
Expand All @@ -231,7 +225,6 @@ def process(self, state):

class GridTileBatteryChargeRemainingTime(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_HOURGLASS
icon_color_fg = Color(64, 255, 64, 255)

def process(self, state):
value = state.get("sensor.delta_2_max_downstairs_charge_remaining_time", 0)
Expand All @@ -242,7 +235,6 @@ def process(self, state):

class GridTileBatteryAcInPower(HomeAssistantEntityGridTile):
icon = MaterialIcons.MDI_POWER
icon_color_fg = Color(255, 64, 64, 255)

def process(self, state):
value = state.get("sensor.delta_2_max_downstairs_ac_in_power", 0)
Expand Down
1 change: 1 addition & 0 deletions wideboy/sprites/homeassistant/entity_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def render(self) -> None:
self.font_name,
self.font_size,
color_fg=Color(255, 255, 255, 255),
color_outline=Color(0, 0, 0, 255),
)
self.image.blit(title_surface, (cx + 1, cy - 1))
by += title_surface.get_rect().height
Expand Down

0 comments on commit 008b16f

Please sign in to comment.