WIP #212 Light card
This commit is contained in:
parent
1499a91ef7
commit
78d6b38b92
@ -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;
|
||||
|
85
lib/cards/light_card.dart
Normal file
85
lib/cards/light_card.dart
Normal file
@ -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: <Widget>[
|
||||
SfRadialGauge(
|
||||
axes: <RadialAxis>[
|
||||
RadialAxis(
|
||||
maximum: 255,
|
||||
minimum: 0,
|
||||
showLabels: false,
|
||||
showTicks: false,
|
||||
canScaleToFit: true,
|
||||
axisLineStyle: AxisLineStyle(
|
||||
thickness: 0.05,
|
||||
thicknessUnit: GaugeSizeUnit.factor,
|
||||
color: HAClientTheme().getDisabledStateColor(context)
|
||||
),
|
||||
pointers: <GaugePointer>[
|
||||
/*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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ part of '../main.dart';
|
||||
class EntityWrapper {
|
||||
|
||||
String overrideName;
|
||||
final String overrideIcon;
|
||||
String overrideIcon;
|
||||
final bool stateColor;
|
||||
EntityUIAction uiAction;
|
||||
Entity entity;
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user