Entity actions moved from data model. Colors refactored
This commit is contained in:
parent
2db432ccd2
commit
2fb8d8e26b
@ -245,14 +245,6 @@ class HassioDataModel {
|
|||||||
composedEntity["display_name"] = "${entity["attributes"]!=null ? entity["attributes"]["friendly_name"] ?? entity["attributes"]["name"] : "_"}";
|
composedEntity["display_name"] = "${entity["attributes"]!=null ? entity["attributes"]["friendly_name"] ?? entity["attributes"]["name"] : "_"}";
|
||||||
composedEntity["domain"] = entityDomain;
|
composedEntity["domain"] = entityDomain;
|
||||||
|
|
||||||
if ((entityDomain == "automation") || (entityDomain == "switch") || (entityDomain == "light")) {
|
|
||||||
composedEntity["actionType"] = "switch";
|
|
||||||
} else if ((entityDomain == "script") || (entityDomain == "scene")) {
|
|
||||||
composedEntity["actionType"] = "statelessIcon";
|
|
||||||
} else {
|
|
||||||
composedEntity["actionType"] = "stateText";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (composedEntity["attributes"] != null) {
|
if (composedEntity["attributes"] != null) {
|
||||||
if ((entityDomain == "group")&&(composedEntity["attributes"]["view"] == true)) {
|
if ((entityDomain == "group")&&(composedEntity["attributes"]["view"] == true)) {
|
||||||
uiGroups.add(entityId);
|
uiGroups.add(entityId);
|
||||||
|
@ -59,13 +59,17 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
StreamSubscription _stateSubscription;
|
StreamSubscription _stateSubscription;
|
||||||
StreamSubscription _settingsSubscription;
|
StreamSubscription _settingsSubscription;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
Map _stateIconColors = {
|
Map<String, Color> _stateIconColors = {
|
||||||
"on": Colors.amber,
|
"on": Colors.amber,
|
||||||
"off": Colors.blueGrey,
|
"off": Color.fromRGBO(68, 115, 158, 1.0),
|
||||||
"unavailable": Colors.black12,
|
"unavailable": Colors.black12,
|
||||||
"unknown": Colors.black12,
|
"unknown": Colors.black12,
|
||||||
"playing": Colors.amber
|
"playing": Colors.amber
|
||||||
};
|
};
|
||||||
|
Map<String, Color> _badgeColors = {
|
||||||
|
"default": Color.fromRGBO(223, 76, 30, 1.0),
|
||||||
|
"binary_sensor": Color.fromRGBO(3, 155, 229, 1.0)
|
||||||
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -223,6 +227,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
double iconSize = 26.0;
|
double iconSize = 26.0;
|
||||||
Widget badgeIcon;
|
Widget badgeIcon;
|
||||||
String badgeTextValue;
|
String badgeTextValue;
|
||||||
|
Color iconColor = _badgeColors[data["domain"]] ?? _badgeColors["default"];
|
||||||
switch (data["domain"]) {
|
switch (data["domain"]) {
|
||||||
case "sun": {
|
case "sun": {
|
||||||
badgeIcon = data["state"] == "below_horizon" ?
|
badgeIcon = data["state"] == "below_horizon" ?
|
||||||
@ -270,7 +275,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
// Circle shape
|
// Circle shape
|
||||||
//shape: BoxShape.circle,
|
//shape: BoxShape.circle,
|
||||||
color: Colors.redAccent,
|
color: iconColor,
|
||||||
borderRadius: BorderRadius.circular(9.0),
|
borderRadius: BorderRadius.circular(9.0),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -288,7 +293,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
// The border you want
|
// The border you want
|
||||||
border: new Border.all(
|
border: new Border.all(
|
||||||
width: 2.0,
|
width: 2.0,
|
||||||
color: Colors.redAccent,
|
color: iconColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
@ -364,7 +369,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
entities.add(new ListTile(
|
entities.add(new ListTile(
|
||||||
leading: MaterialDesignIcons.createIconFromEntityData(data, 28.0, _stateIconColors[data["state"]] ?? Colors.blueGrey),
|
leading: MaterialDesignIcons.createIconFromEntityData(data, 28.0, _stateIconColors[data["state"]] ?? Colors.blueGrey),
|
||||||
//subtitle: Text("${data['entity_id']}"),
|
//subtitle: Text("${data['entity_id']}"),
|
||||||
trailing: _buildEntityStateWidget(data),
|
trailing: _buildEntityActionWidget(data),
|
||||||
title: Text(
|
title: Text(
|
||||||
"${data["display_name"]}",
|
"${data["display_name"]}",
|
||||||
overflow: TextOverflow.fade,
|
overflow: TextOverflow.fade,
|
||||||
@ -376,10 +381,13 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEntityStateWidget(data) {
|
Widget _buildEntityActionWidget(data) {
|
||||||
String entityId = data["entity_id"];
|
String entityId = data["entity_id"];
|
||||||
Widget result;
|
Widget result;
|
||||||
if (data["actionType"] == "switch") {
|
switch (data["domain"]) {
|
||||||
|
case "automation":
|
||||||
|
case "switch":
|
||||||
|
case "light": {
|
||||||
result = Switch(
|
result = Switch(
|
||||||
value: (data["state"] == "on"),
|
value: (data["state"] == "on"),
|
||||||
onChanged: ((state) {
|
onChanged: ((state) {
|
||||||
@ -390,7 +398,11 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else if (data["actionType"] == "statelessIcon") {
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "script":
|
||||||
|
case "scene": {
|
||||||
result = SizedBox(
|
result = SizedBox(
|
||||||
width: 60.0,
|
width: 60.0,
|
||||||
child: FlatButton(
|
child: FlatButton(
|
||||||
@ -402,8 +414,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(fontSize: 16.0, color: Colors.blue),
|
style: new TextStyle(fontSize: 16.0, color: Colors.blue),
|
||||||
),
|
),
|
||||||
));
|
)
|
||||||
} else {
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
result = Padding(
|
result = Padding(
|
||||||
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
|
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -411,8 +427,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
|
|||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
fontSize: 16.0,
|
fontSize: 16.0,
|
||||||
)));
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*return SizedBox(
|
/*return SizedBox(
|
||||||
width: 60.0,
|
width: 60.0,
|
||||||
// height: double.infinity,
|
// height: double.infinity,
|
||||||
|
Reference in New Issue
Block a user