WIP #55
This commit is contained in:
parent
0e3474bbcb
commit
54e00c3403
@ -47,5 +47,29 @@ class MediaPlayerEntity extends Entity {
|
||||
bool get supportTurnOff => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_TURN_OFF) ==
|
||||
MediaPlayerEntity.SUPPORT_TURN_OFF);
|
||||
bool get supportPlayMedia => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_PLAY_MEDIA) ==
|
||||
MediaPlayerEntity.SUPPORT_PLAY_MEDIA);
|
||||
bool get supportVolumeStep => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_VOLUME_STEP) ==
|
||||
MediaPlayerEntity.SUPPORT_VOLUME_STEP);
|
||||
bool get supportSelectSource => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_SELECT_SOURCE) ==
|
||||
MediaPlayerEntity.SUPPORT_SELECT_SOURCE);
|
||||
bool get supportStop => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_STOP) ==
|
||||
MediaPlayerEntity.SUPPORT_STOP);
|
||||
bool get supportClearPlaylist => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_CLEAR_PLAYLIST) ==
|
||||
MediaPlayerEntity.SUPPORT_CLEAR_PLAYLIST);
|
||||
bool get supportPlay => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_PLAY) ==
|
||||
MediaPlayerEntity.SUPPORT_PLAY);
|
||||
bool get supportShuffleSet => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_SHUFFLE_SET) ==
|
||||
MediaPlayerEntity.SUPPORT_SHUFFLE_SET);
|
||||
bool get supportSelectSoundMode => ((attributes["supported_features"] &
|
||||
MediaPlayerEntity.SUPPORT_SELECT_SOUND_MODE) ==
|
||||
MediaPlayerEntity.SUPPORT_SELECT_SOUND_MODE);
|
||||
|
||||
}
|
@ -38,6 +38,9 @@ class EntityCollection {
|
||||
case 'sun': {
|
||||
return SunEntity(rawEntityData);
|
||||
}
|
||||
case "media_player": {
|
||||
return MediaPlayerEntity(rawEntityData);
|
||||
}
|
||||
case 'sensor': {
|
||||
return SensorEntity(rawEntityData);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ class HomeAssistant {
|
||||
}
|
||||
} else if (data["type"] == "event") {
|
||||
if ((data["event"] != null) && (data["event"]["event_type"] == "state_changed")) {
|
||||
//TheLogger.debug("[Received] <== ${data['type']}.${data["event"]["event_type"]}: ${data["event"]["data"]["entity_id"]}");
|
||||
TheLogger.debug("[Received] <== ${data['type']}.${data["event"]["event_type"]}: ${data["event"]["data"]["entity_id"]}");
|
||||
_handleEntityStateChange(data["event"]["data"]);
|
||||
} else if (data["event"] != null) {
|
||||
TheLogger.warning("Unhandled event type: ${data["event"]["event_type"]}");
|
||||
|
@ -23,6 +23,12 @@ class HACard {
|
||||
);
|
||||
}
|
||||
|
||||
case "media-control": {
|
||||
return MediaControlCardWidget(
|
||||
card: this,
|
||||
);
|
||||
}
|
||||
|
||||
case "weather-forecast":
|
||||
case "thermostat":
|
||||
case "sensor":
|
||||
@ -35,8 +41,7 @@ class HACard {
|
||||
case "gauge":
|
||||
case "entity-button":
|
||||
case "conditional":
|
||||
case "alarm-panel":
|
||||
case "media-control": {
|
||||
case "alarm-panel": {
|
||||
return UnsupportedCardWidget(
|
||||
card: this,
|
||||
);
|
||||
|
@ -11,17 +11,81 @@ class MediaControlCardWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if ((card.linkedEntity!= null) && (card.linkedEntity.isHidden)) {
|
||||
if ((card.linkedEntity == null) || (card.linkedEntity.isHidden)) {
|
||||
return Container(width: 0.0, height: 0.0,);
|
||||
}
|
||||
List<Widget> body = [];
|
||||
if (homeAssistantWebHost != null) {
|
||||
body.add(Stack(
|
||||
alignment: AlignmentDirectional.topEnd,
|
||||
children: <Widget>[
|
||||
_buildImage(),
|
||||
Positioned(
|
||||
bottom: 0.0,
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
child: Container(
|
||||
height: 80.0,
|
||||
color: Colors.black26,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0.0,
|
||||
left: 0.0,
|
||||
child: _buildState(),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
return Card(
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: body
|
||||
child: Column(
|
||||
//crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: body
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildState() {
|
||||
TextStyle style = TextStyle(
|
||||
fontSize: 14.0,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.normal,
|
||||
height: 1.2
|
||||
);
|
||||
List<Widget> states = [];
|
||||
states.add(Text("${card.linkedEntity.displayName}", style: style));
|
||||
if (card.linkedEntity.state == null || card.linkedEntity.state == "off" || card.linkedEntity.state == "unavailable") {
|
||||
states.add(Text("${card.linkedEntity.state}", style: style.apply(fontSizeDelta: 4.0),));
|
||||
} else {
|
||||
states.add(Text("${card.linkedEntity.attributes['media_title'] ?? '-'}", style: style.apply(fontSizeDelta: 6.0, fontWeightDelta: 50),));
|
||||
states.add(Text("${card.linkedEntity.attributes['media_artist'] ?? '-'}", style: style.apply(fontSizeDelta: 4.0),));
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: Entity.leftWidgetPadding, right: Entity.rightWidgetPadding),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: states,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImage() {
|
||||
if (homeAssistantWebHost != null && card.linkedEntity.entityPicture != null) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Image(
|
||||
image: CachedNetworkImageProvider("$homeAssistantWebHost${card.linkedEntity.entityPicture}"),
|
||||
height: 300.0,
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
color: Colors.blue,
|
||||
height: 80.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user