Compare commits

...

8 Commits

Author SHA1 Message Date
f77e46de37 Version 0.3.12 2018-12-14 17:04:52 +02:00
cda17b1217 Resolves #232 2018-12-14 17:03:18 +02:00
be560769ef Resolves #243 2018-12-14 16:57:11 +02:00
3815800e32 Resolves #253 removing trash characters from state string 2018-12-14 16:48:35 +02:00
a3226311a2 Fix default tap actions 2018-12-14 16:31:41 +02:00
79669243c2 Remove some logging 2018-12-14 16:01:13 +02:00
fdc81f6ea4 Resolves #237 2018-12-14 15:59:47 +02:00
7fe44459e7 Resolves #252, Resolves #249 2018-12-14 14:28:23 +02:00
10 changed files with 122 additions and 90 deletions

View File

@ -30,11 +30,49 @@ class EntityState {
static const problem = 'problem'; static const problem = 'problem';
} }
class EntityTapAction { class EntityUIAction {
static const moreInfo = 'more-info'; static const moreInfo = 'more-info';
static const toggle = 'toggle'; static const toggle = 'toggle';
static const callService = 'call-service'; static const callService = 'call-service';
static const navigate = 'navigate';
static const none = 'none'; static const none = 'none';
String tapAction = EntityUIAction.moreInfo;
String tapNavigationPath;
String tapService;
Map<String, dynamic> tapServiceData;
String holdAction = EntityUIAction.none;
String holdNavigationPath;
String holdService;
Map<String, dynamic> holdServiceData;
EntityUIAction({rawEntityData}) {
if (rawEntityData != null) {
if (rawEntityData["tap_action"] != null) {
if (rawEntityData["tap_action"] is String) {
tapAction = rawEntityData["tap_action"];
} else {
tapAction =
rawEntityData["tap_action"]["action"] ?? EntityUIAction.moreInfo;
tapNavigationPath = rawEntityData["tap_action"]["navigation_path"];
tapService = rawEntityData["tap_action"]["service"];
tapServiceData = rawEntityData["tap_action"]["service_data"];
}
}
if (rawEntityData["hold_action"] != null) {
if (rawEntityData["hold_action"] is String) {
holdAction = rawEntityData["hold_action"];
} else {
holdAction =
rawEntityData["hold_action"]["action"] ?? EntityUIAction.none;
holdNavigationPath = rawEntityData["hold_action"]["navigation_path"];
holdService = rawEntityData["hold_action"]["service"];
holdServiceData = rawEntityData["hold_action"]["service_data"];
}
}
}
}
} }
class CardType { class CardType {

View File

@ -20,6 +20,7 @@ class Entity {
List<Entity> childEntities = []; List<Entity> childEntities = [];
List<String> attributesToShow = ["all"]; List<String> attributesToShow = ["all"];
String deviceClass;
EntityHistoryConfig historyConfig = EntityHistoryConfig( EntityHistoryConfig historyConfig = EntityHistoryConfig(
chartType: EntityHistoryWidgetType.simple chartType: EntityHistoryWidgetType.simple
); );
@ -27,7 +28,6 @@ class Entity {
String get displayName => String get displayName =>
attributes["friendly_name"] ?? (attributes["name"] ?? entityId.split(".")[1].replaceAll("_", " ")); attributes["friendly_name"] ?? (attributes["name"] ?? entityId.split(".")[1].replaceAll("_", " "));
String get deviceClass => attributes["device_class"] ?? null;
bool get isView => bool get isView =>
(domain == "group") && (domain == "group") &&
(attributes != null ? attributes["view"] ?? false : false); (attributes != null ? attributes["view"] ?? false : false);
@ -50,6 +50,7 @@ class Entity {
attributes = rawData["attributes"] ?? {}; attributes = rawData["attributes"] ?? {};
domain = rawData["entity_id"].split(".")[0]; domain = rawData["entity_id"].split(".")[0];
entityId = rawData["entity_id"]; entityId = rawData["entity_id"];
deviceClass = attributes["device_class"];
state = rawData["state"]; state = rawData["state"];
_lastUpdated = DateTime.tryParse(rawData["last_updated"]); _lastUpdated = DateTime.tryParse(rawData["last_updated"]);
} }

View File

@ -4,12 +4,7 @@ class EntityWrapper {
String displayName; String displayName;
String icon; String icon;
String tapAction; EntityUIAction uiAction;
String holdAction;
String tapActionService;
Map<String, dynamic> tapActionServiceData;
String holdActionService;
Map<String, dynamic> holdActionServiceData;
Entity entity; Entity entity;
@ -17,59 +12,68 @@ class EntityWrapper {
this.entity, this.entity,
String icon, String icon,
String displayName, String displayName,
this.tapAction: EntityTapAction.moreInfo, this.uiAction
this.holdAction: EntityTapAction.none,
this.tapActionService,
this.tapActionServiceData,
this.holdActionService,
this.holdActionServiceData
}) { }) {
this.icon = icon ?? entity.icon; this.icon = icon ?? entity.icon;
this.displayName = displayName ?? entity.displayName; this.displayName = displayName ?? entity.displayName;
if (this.uiAction == null) {
this.uiAction = EntityUIAction();
}
} }
void handleTap() { void handleTap() {
TheLogger.debug(tapAction); switch (uiAction.tapAction) {
switch (tapAction) { case EntityUIAction.toggle: {
case EntityTapAction.toggle: {
eventBus.fire( eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entity.entityId, null)); ServiceCallEvent("homeassistant", "toggle", entity.entityId, null));
break; break;
} }
case EntityTapAction.callService: { case EntityUIAction.callService: {
if (uiAction.tapService != null) {
eventBus.fire( eventBus.fire(
ServiceCallEvent(tapActionService.split(".")[0], tapActionService.split(".")[1], null, tapActionServiceData)); ServiceCallEvent(uiAction.tapService.split(".")[0],
uiAction.tapService.split(".")[1], null,
uiAction.tapServiceData));
}
break; break;
} }
case EntityTapAction.none: { case EntityUIAction.none: {
break;
}
case EntityUIAction.moreInfo: {
eventBus.fire(
new ShowEntityPageEvent(entity));
break; break;
} }
default: { default: {
eventBus.fire(
new ShowEntityPageEvent(entity));
break; break;
} }
} }
} }
void handleHold() { void handleHold() {
switch (holdAction) { switch (uiAction.holdAction) {
case EntityTapAction.toggle: { case EntityUIAction.toggle: {
eventBus.fire( eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entity.entityId, null)); ServiceCallEvent("homeassistant", "toggle", entity.entityId, null));
break; break;
} }
case EntityTapAction.callService: { case EntityUIAction.callService: {
if (uiAction.holdService != null) {
eventBus.fire( eventBus.fire(
ServiceCallEvent(tapActionService.split(".")[0], tapActionService.split(".")[1], null, tapActionServiceData)); ServiceCallEvent(uiAction.holdService.split(".")[0],
uiAction.holdService.split(".")[1], null,
uiAction.holdServiceData));
}
break; break;
} }
case EntityTapAction.moreInfo: { case EntityUIAction.moreInfo: {
eventBus.fire( eventBus.fire(
new ShowEntityPageEvent(entity)); new ShowEntityPageEvent(entity));
break; break;

View File

@ -12,10 +12,15 @@ class SimpleEntityState extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final entityModel = EntityModel.of(context); final entityModel = EntityModel.of(context);
String state = entityModel.entityWrapper.entity.state ?? "";
state = state.replaceAll("\n", "").replaceAll("\t", " ").trim();
while (state.contains(" ")){
state = state.replaceAll(" ", " ");
}
Widget result = Padding( Widget result = Padding(
padding: padding, padding: padding,
child: Text( child: Text(
"${entityModel.entityWrapper.entity.state} ${entityModel.entityWrapper.entity.unitOfMeasurement}", "$state ${entityModel.entityWrapper.entity.unitOfMeasurement}",
textAlign: textAlign, textAlign: textAlign,
maxLines: maxLines, maxLines: maxLines,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,

View File

@ -450,28 +450,12 @@ class HomeAssistant {
} else { } else {
if (entities.isExist(rawEntity["entity"])) { if (entities.isExist(rawEntity["entity"])) {
Entity e = entities.get(rawEntity["entity"]); Entity e = entities.get(rawEntity["entity"]);
String tapAction = EntityTapAction.moreInfo;
String holdAction = EntityTapAction.none;
if (card.type == CardType.glance || card.type == CardType.entityButton) {
if (rawEntity["tap_action"] != null) {
if (rawEntity["tap_action"] is String) {
tapAction = rawEntity["tap_action"];
holdAction = rawEntity["hold_action"];
} else {
tapAction = rawEntity["tap_action"]["action"];
holdAction = rawEntity["hold_action"]["action"];
}
}
}
card.entities.add( card.entities.add(
EntityWrapper( EntityWrapper(
entity: e, entity: e,
displayName: rawEntity["name"], displayName: rawEntity["name"],
icon: rawEntity["icon"], icon: rawEntity["icon"],
tapAction: tapAction, uiAction: EntityUIAction(rawEntityData: rawEntity)
holdAction: holdAction,
//tapActionService: rawEntity["service"],
//tapActionServiceData: rawEntity["service_data"] ?? {"entity_id": e.entityId}
) )
); );
} }
@ -479,26 +463,12 @@ class HomeAssistant {
}); });
if (rawCard["entity"] != null) { if (rawCard["entity"] != null) {
var en = rawCard["entity"]; var en = rawCard["entity"];
String tapAction = EntityTapAction.moreInfo;
String holdAction = EntityTapAction.none;
if (rawCard["tap_action"] != null) {
if (rawCard["tap_action"] is String) {
tapAction = rawCard["tap_action"];
holdAction = rawCard["hold_action"];
} else {
tapAction = rawCard["tap_action"]["action"];
holdAction = rawCard["hold_action"]["action"];
}
}
if (en is String) { if (en is String) {
if (entities.isExist(en)) { if (entities.isExist(en)) {
Entity e = entities.get(en); Entity e = entities.get(en);
card.linkedEntityWrapper = EntityWrapper( card.linkedEntityWrapper = EntityWrapper(
entity: e, entity: e,
tapAction: tapAction, uiAction: EntityUIAction(rawEntityData: rawCard)
holdAction: holdAction,
//tapActionService: rawCard["service"],
//tapActionServiceData: rawCard["service_data"] ?? {"entity_id": e.entityId}
); );
} }
} else { } else {
@ -508,10 +478,7 @@ class HomeAssistant {
entity: e, entity: e,
icon: en["icon"], icon: en["icon"],
displayName: en["name"], displayName: en["name"],
tapAction: tapAction, uiAction: EntityUIAction(rawEntityData: rawCard)
holdAction: holdAction,
tapActionService: rawCard["service"],
tapActionServiceData: rawCard["service_data"] ?? {"entity_id": e.entityId}
); );
} }
} }

View File

@ -85,7 +85,7 @@ part 'ui_widgets/card_header_widget.dart';
EventBus eventBus = new EventBus(); EventBus eventBus = new EventBus();
const String appName = "HA Client"; const String appName = "HA Client";
const appVersion = "0.3.11"; const appVersion = "0.3.12";
String homeAssistantWebHost; String homeAssistantWebHost;

View File

@ -41,8 +41,8 @@ class MaterialDesignIcons {
"binary_sensor.heat.off": "mdi:thermometer", "binary_sensor.heat.off": "mdi:thermometer",
"binary_sensor.light.on": "mdi:brightness-7", "binary_sensor.light.on": "mdi:brightness-7",
"binary_sensor.light.off": "mdi:brightness-5", "binary_sensor.light.off": "mdi:brightness-5",
//"binary_sensor.lock.on": "mdi:", "binary_sensor.lock.on": "mdi:lock-open",
//"binary_sensor.lock.off": "mdi:", "binary_sensor.lock.off": "mdi:lock",
"binary_sensor.moisture.on": "mdi:water", "binary_sensor.moisture.on": "mdi:water",
"binary_sensor.moisture.off": "mdi:water-off", "binary_sensor.moisture.off": "mdi:water-off",
"binary_sensor.motion.on": "mdi:run", "binary_sensor.motion.on": "mdi:run",
@ -59,8 +59,8 @@ class MaterialDesignIcons {
"binary_sensor.power.off": "mdi:verified", "binary_sensor.power.off": "mdi:verified",
//"binary_sensor.presence.on": "mdi:", //"binary_sensor.presence.on": "mdi:",
//"binary_sensor.presence.off": "mdi:", //"binary_sensor.presence.off": "mdi:",
//"binary_sensor.problem.on": "mdi:", "binary_sensor.problem.on": "mdi:alert-outline",
//"binary_sensor.problem.off": "mdi:", "binary_sensor.problem.off": "mdi:check-outline",
"binary_sensor.safety.on": "mdi:alert", "binary_sensor.safety.on": "mdi:alert",
"binary_sensor.safety.off": "mdi:verified", "binary_sensor.safety.off": "mdi:verified",
"binary_sensor.smoke.on": "mdi:alert", "binary_sensor.smoke.on": "mdi:alert",
@ -69,13 +69,13 @@ class MaterialDesignIcons {
"binary_sensor.sound.off": "mdi:music-note-off", "binary_sensor.sound.off": "mdi:music-note-off",
"binary_sensor.vibration.on": "mdi:vibrate", "binary_sensor.vibration.on": "mdi:vibrate",
"binary_sensor.vibration.off": "mdi:mdi-crop-portrait", "binary_sensor.vibration.off": "mdi:mdi-crop-portrait",
//"binary_sensor.window.on": "mdi:", "binary_sensor.window.on": "mdi:window-open",
//"binary_sensor.window.off": "mdi:", "binary_sensor.window.off": "mdi:window-closed",
"sensor.battery": "mdi:battery-80", "sensor.battery": "mdi:battery-80",
"sensor.humidity": "mdi:water-percent", "sensor.humidity": "mdi:water-percent",
//"sensor.illuminance": "mdi:", //"sensor.illuminance": "mdi:",
"sensor.temperature": "mdi:thermometer", "sensor.temperature": "mdi:thermometer",
//"cover.window": "mdi:", "cover.window": "mdi:mdi:window-closed",
"cover.garage.closed": "mdi:garage", "cover.garage.closed": "mdi:garage",
"cover.garage.open": "mdi:garage-open", "cover.garage.open": "mdi:garage-open",
"cover.garage.opening": "mdi:garage-open", "cover.garage.opening": "mdi:garage-open",

View File

@ -150,6 +150,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
_newHassioPort = value; _newHassioPort = value;
} }
), ),
new Text(
"Try ports 80 and 443 if default is not working and you don't know why.",
style: TextStyle(color: Colors.grey),
),
new Row( new Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@ -170,6 +174,10 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
) )
], ],
), ),
new Text(
"You should use access token for HA >= 0.84.1. Legacy password will not work there.",
style: TextStyle(color: Colors.grey),
),
new TextField( new TextField(
decoration: InputDecoration( decoration: InputDecoration(
labelText: _newAuthType == "access_token" ? "Access token" : "API password" labelText: _newAuthType == "access_token" ? "Access token" : "API password"

View File

@ -150,6 +150,9 @@ class CardWidget extends StatelessWidget {
} }
Widget _buildMediaControlsCard(BuildContext context) { Widget _buildMediaControlsCard(BuildContext context) {
if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) {
return Container(width: 0, height: 0,);
} else {
return Card( return Card(
child: EntityModel( child: EntityModel(
entityWrapper: card.linkedEntityWrapper, entityWrapper: card.linkedEntityWrapper,
@ -158,9 +161,14 @@ class CardWidget extends StatelessWidget {
) )
); );
} }
}
Widget _buildEntityButtonCard(BuildContext context) { Widget _buildEntityButtonCard(BuildContext context) {
card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ?? card.linkedEntityWrapper.displayName.toUpperCase(); if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) {
return Container(width: 0, height: 0,);
} else {
card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ??
card.linkedEntityWrapper.displayName.toUpperCase();
return Card( return Card(
child: EntityModel( child: EntityModel(
entityWrapper: card.linkedEntityWrapper, entityWrapper: card.linkedEntityWrapper,
@ -169,6 +177,7 @@ class CardWidget extends StatelessWidget {
) )
); );
} }
}
Widget _buildUnsupportedCard(BuildContext context) { Widget _buildUnsupportedCard(BuildContext context) {
List<Widget> body = []; List<Widget> body = [];

View File

@ -1,7 +1,7 @@
name: hass_client name: hass_client
description: Home Assistant Android Client description: Home Assistant Android Client
version: 0.3.11+78 version: 0.3.12+79
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.0.0-dev.68.0 <3.0.0"