From d0931b096320f721d12e60e9d4ec095341d44cf1 Mon Sep 17 00:00:00 2001 From: Louis King Date: Fri, 21 Jun 2024 21:21:23 +0100 Subject: [PATCH] Tidying --- wideboy/sprites/tile_grid/helpers.py | 2 + wideboy/systems/scene/entity_tiles.py | 157 +++----------------------- 2 files changed, 20 insertions(+), 139 deletions(-) diff --git a/wideboy/sprites/tile_grid/helpers.py b/wideboy/sprites/tile_grid/helpers.py index 3bdf3c7..d36abd9 100644 --- a/wideboy/sprites/tile_grid/helpers.py +++ b/wideboy/sprites/tile_grid/helpers.py @@ -88,6 +88,8 @@ class FontAwesomeIcons: ICON_FA_SHIELD_HALVED = 0xF3ED ICON_FA_BUG = 0xF188 ICON_FA_WORM = 0xE599 + ICON_FA_CHEVRON_UP = 0xF077 + ICON_FA_CHEVRON_DOWN = 0xF078 # HELPER FUNCTIONS diff --git a/wideboy/systems/scene/entity_tiles.py b/wideboy/systems/scene/entity_tiles.py index f8f9510..ca2865b 100644 --- a/wideboy/systems/scene/entity_tiles.py +++ b/wideboy/systems/scene/entity_tiles.py @@ -254,15 +254,6 @@ def label(self): return template_if_defined(self.value, "{:.0f}%") -# Temperature Tiles - - -class BaseCellTemperate(GridCell): - @property - def label(self): - return template_if_defined(self.value, "{:.0f}°") - - # Energy Tiles @@ -362,25 +353,24 @@ def icon_color_background(self): ) -class CellGasAccumulativeCost(GridCell): - entity_id = "sensor.octopus_energy_gas_current_accumulative_cost" - icon_codepoint = FontAwesomeIcons.ICON_FA_FIRE_FLAME_SIMPLE - limit = 2.00 - limit_high = 3.00 +class CellBatteryUpstairs(GridCell): + entity_id = "sensor.delta_2_max_upstairs_battery_level" + icon_codepoint = FontAwesomeIcons.ICON_FA_CHEVRON_UP + limit = 100 @property def label(self): - return template_if_defined(self.value, "£{:.2f}") + return template_if_defined(self.value, "{:.0f}%") @property def open(self): - return is_defined(self.value) and self.value > self.limit + return is_defined(self.value) and int(self.value) < self.limit @property def cell_color_background(self): return ( CommonColors.COLOR_RED_DARK - if is_defined(self.value) and self.value > self.limit_high + if is_defined(self.value) and self.value < 50 else CommonColors.COLOR_GREY_DARK ) @@ -388,47 +378,29 @@ def cell_color_background(self): def icon_color_background(self): return ( CommonColors.COLOR_RED - if is_defined(self.value) and self.value > self.limit_high + if is_defined(self.value) and self.value < 50 else CommonColors.COLOR_GREY ) class CellBatteryDownstairs(GridCell): entity_id = "sensor.delta_2_max_downstairs_battery_level" - limit = 50 + icon_codepoint = FontAwesomeIcons.ICON_FA_CHEVRON_DOWN + limit = 100 @property def label(self): - time_remaining = self.state.get( - "sensor.delta_2_max_downstairs_discharge_remaining_time" - ) - print("TIME", time_remaining) return template_if_defined(self.value, "{:.0f}%") @property def open(self): - return is_defined(self.value) and int(self.value) < 50 - - @property - def icon_codepoint(self): - if not is_defined(self.value): - return None - if self.value < 20: - return FontAwesomeIcons.ICON_FA_BATTERY_EMPTY - elif self.value < 40: - return FontAwesomeIcons.ICON_FA_BATTERY_QUARTER - elif self.value < 60: - return FontAwesomeIcons.ICON_FA_BATTERY_HALF - elif self.value < 80: - return FontAwesomeIcons.ICON_FA_BATTERY_THREE_QUARTERS - else: - return FontAwesomeIcons.ICON_FA_BATTERY_FULL + return is_defined(self.value) and int(self.value) < self.limit @property def cell_color_background(self): return ( CommonColors.COLOR_RED_DARK - if is_defined(self.value) and self.value < self.limit + if is_defined(self.value) and self.value < 50 else CommonColors.COLOR_GREY_DARK ) @@ -436,110 +408,18 @@ def cell_color_background(self): def icon_color_background(self): return ( CommonColors.COLOR_RED - if is_defined(self.value) and self.value < self.limit + if is_defined(self.value) and self.value < 50 else CommonColors.COLOR_GREY ) -class CellBatteryUpstairs(GridCell): - entity_id = "sensor.delta_2_max_upstairs_battery_level" - limit = 50 - - @property - def label(self): - return template_if_defined(self.value, "{:.0f}%") - - @property - def open(self): - return is_defined(self.value) and int(self.value) < 50 - - @property - def icon_codepoint(self): - if not is_defined(self.value): - return None - if self.value < 20: - return FontAwesomeIcons.ICON_FA_BATTERY_EMPTY - elif self.value < 40: - return FontAwesomeIcons.ICON_FA_BATTERY_QUARTER - elif self.value < 60: - return FontAwesomeIcons.ICON_FA_BATTERY_HALF - elif self.value < 80: - return FontAwesomeIcons.ICON_FA_BATTERY_THREE_QUARTERS - else: - return FontAwesomeIcons.ICON_FA_BATTERY_FULL - - @property - def cell_color_background(self): - return ( - CommonColors.COLOR_RED_DARK - if is_defined(self.value) and self.value < self.limit - else CommonColors.COLOR_GREY_DARK - ) - - @property - def icon_color_background(self): - return ( - CommonColors.COLOR_RED - if is_defined(self.value) and self.value < self.limit - else CommonColors.COLOR_GREY - ) - - -class CellBatteryACInput(GridCell): - entity_id = "sensor.delta_2_max_downstairs_ac_in_power" - icon_codepoint = FontAwesomeIcons.ICON_FA_PLUG_CIRCLE_PLUS - - @property - def open(self): - return is_defined(self.value) and self.value > 0 - - @property - def label(self): - return format_watts(self.value) - - -class CellBatteryACOutput(GridCell): - entity_id = "sensor.delta_2_max_downstairs_ac_out_power" - icon_codepoint = FontAwesomeIcons.ICON_FA_PLUG_CIRCLE_MINUS - - @property - def open(self): - return is_defined(self.value) and self.value > 0 - - @property - def label(self): - return format_watts(self.value) - - -class CellBatteryChargeRemainingTime(GridCell): - entity_id = "sensor.delta_2_max_downstairs_charge_remaining_time" - icon_codepoint = FontAwesomeIcons.ICON_FA_PLUG_CIRCLE_PLUS - icon_color_background = CommonColors.COLOR_GREEN_DARK - - @property - def open(self): - return is_defined(self.value) and self.value > 0 - - @property - def label(self): - return format_minutes(self.value) - - -class CellBatteryDischargeRemainingTime(GridCell): - entity_id = "sensor.delta_2_max_downstairs_discharge_remaining_time" - icon_codepoint = FontAwesomeIcons.ICON_FA_PLUG_CIRCLE_MINUS - icon_color_background = CommonColors.COLOR_RED_DARK +# Weather Tiles - @property - def open(self): - return is_defined(self.value) and self.value > 0 +class BaseCellTemperate(GridCell): @property def label(self): - return format_minutes(self.value) - - -# Weather Tiles + return template_if_defined(self.value, "{:.0f}°") class CellWeatherTemperature(BaseCellTemperate): @@ -632,14 +512,11 @@ class TestTallCell(TallGridCell): CellSpeedTestDownload, CellSpeedTestUpload, CellSpeedTestPing, - CellDateDogsFleaTreatment, - CellDateDogsWormTreatment, ], [ CellElectricityDemand, CellElectricityRate, CellElectricityAccumulativeCost, - CellGasAccumulativeCost, CellBatteryUpstairs, CellBatteryDownstairs, ], @@ -647,5 +524,7 @@ class TestTallCell(TallGridCell): CellWeatherTemperature, CellWeatherWindSpeed, CellWeatherRainProbability, + CellDateDogsFleaTreatment, + CellDateDogsWormTreatment, ], ]