diff --git a/lib/cards/card.class.dart b/lib/cards/card.class.dart index 988b5ce..1fdfc82 100644 --- a/lib/cards/card.class.dart +++ b/lib/cards/card.class.dart @@ -35,8 +35,10 @@ class CardData { case CardType.ALARM_PANEL: return AlarmPanelCardData(rawData); break; - case CardType.ENTITY_BUTTON: case CardType.LIGHT: + return LightCardData(rawData); + break; + case CardType.ENTITY_BUTTON: case CardType.BUTTON: case CardType.PICTURE_ENTITY: return ButtonCardData(rawData); @@ -356,6 +358,39 @@ class AlarmPanelCardData extends CardData { } +class LightCardData extends CardData { + + String name; + String icon; + + @override + Widget buildCardWidget() { + return LightCard(card: this); + } + + LightCardData(rawData) : super(rawData) { + //Parsing card data + name = rawData['name']; + icon = rawData['icon'] is String ? rawData['icon'] : null; + //Parsing entity + var entitiId = rawData["entity"]; + if (entitiId != null && entitiId is String) { + if (HomeAssistant().entities.isExist(entitiId)) { + entities.add(EntityWrapper( + entity: HomeAssistant().entities.get(entitiId), + overrideName: name, + overrideIcon: icon, + uiAction: EntityUIAction() + )); + } else { + entities.add(EntityWrapper(entity: Entity.missed(entitiId))); + } + } else { + entities.add(EntityWrapper(entity: Entity.missed('$entitiId'))); + } + } +} + class ButtonCardData extends CardData { String name; diff --git a/lib/cards/light_card.dart b/lib/cards/light_card.dart new file mode 100644 index 0000000..0f403a3 --- /dev/null +++ b/lib/cards/light_card.dart @@ -0,0 +1,85 @@ +part of '../main.dart'; + +class LightCard extends StatelessWidget { + + final LightCardData card; + + LightCard({Key key, this.card}) : super(key: key); + + @override + Widget build(BuildContext context) { + EntityWrapper entityWrapper = card.entity; + LightEntity entity = entityWrapper.entity; + if (entityWrapper.entity.statelessType == StatelessEntityType.missed) { + return EntityModel( + entityWrapper: card.entity, + child: MissedEntityWidget(), + handleTap: false, + ); + } + entityWrapper.overrideName = card.name ?? + entityWrapper.displayName; + entityWrapper.overrideIcon = card.icon ?? + entityWrapper.icon; + double value = (entity.brightness ?? 0).toDouble(); + + return CardWrapper( + padding: EdgeInsets.all(4), + child: EntityModel( + entityWrapper: entityWrapper, + child: AspectRatio( + aspectRatio: 1.8, + child: Stack( + alignment: Alignment.center, + children: [ + SfRadialGauge( + axes: [ + RadialAxis( + maximum: 255, + minimum: 0, + showLabels: false, + showTicks: false, + canScaleToFit: true, + axisLineStyle: AxisLineStyle( + thickness: 0.05, + thicknessUnit: GaugeSizeUnit.factor, + color: HAClientTheme().getDisabledStateColor(context) + ), + pointers: [ + /*RangePointer( + value: value, + sizeUnit: GaugeSizeUnit.factor, + width: 0.05, + color: HAClientTheme().getOnStateColor(context), + enableAnimation: true, + animationType: AnimationType.bounceOut, + ),*/ + MarkerPointer( + value: value, + markerType: MarkerType.circle, + markerHeight: 20, + markerWidth: 20, + enableDragging: true, + onValueChangeStart: (_) { + Logger.d('Value change start'); + }, + onValueChanging: (args) { + Logger.d('Value changing: ${args.value}'); + }, + color: HAClientTheme().getOnStateColor(context), + enableAnimation: true, + animationType: AnimationType.bounceOut, + ) + ] + ) + ], + ), + ], + ) + ), + handleTap: true + ) + ); + } + +} \ No newline at end of file diff --git a/lib/entities/entity_wrapper.class.dart b/lib/entities/entity_wrapper.class.dart index 55f8d40..8831f52 100644 --- a/lib/entities/entity_wrapper.class.dart +++ b/lib/entities/entity_wrapper.class.dart @@ -3,7 +3,7 @@ part of '../main.dart'; class EntityWrapper { String overrideName; - final String overrideIcon; + String overrideIcon; final bool stateColor; EntityUIAction uiAction; Entity entity; diff --git a/lib/main.dart b/lib/main.dart index c73ce93..f74e696 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -142,6 +142,7 @@ part 'cards/horizontal_srack_card.dart'; part 'cards/markdown_card.dart'; part 'cards/media_control_card.dart'; part 'cards/unsupported_card.dart'; +part 'cards/light_card.dart'; part 'cards/error_card.dart'; part 'cards/vertical_stack_card.dart'; part 'cards/glance_card.dart';