Compare commits

..

1 Commits

Author SHA1 Message Date
3234ffc20c build 713 2019-10-29 18:14:56 +00:00
32 changed files with 238 additions and 422 deletions

View File

@ -3,13 +3,18 @@
<uses-feature android:name="android.hardware.touchscreen" <uses-feature android:name="android.hardware.touchscreen"
android:required="false" /> android:required="false" />
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that <!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method. calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide In most cases you can leave this as-is, but you if you want to provide
@ -19,8 +24,7 @@
android:name=".Application" android:name=".Application"
android:label="HA Client" android:label="HA Client"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true">
android:networkSecurityConfig="@xml/network_security_config">
<meta-data <meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id" android:name="com.google.firebase.messaging.default_notification_channel_id"

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="system"/>
<certificates src="user"/>
</trust-anchors>
</base-config>
</network-security-config>

View File

@ -25,12 +25,9 @@ class _AlarmControlPanelControlsWidgetWidgetState extends State<AlarmControlPane
void _callService(AlarmControlPanelEntity entity, String service) { void _callService(AlarmControlPanelEntity entity, String service) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, service, entity.entityId,
service: service, {"code": "$code"}));
entityId: entity.entityId,
data: {"code": "$code"}
);
setState(() { setState(() {
code = ""; code = "";
}); });
@ -61,11 +58,7 @@ class _AlarmControlPanelControlsWidgetWidgetState extends State<AlarmControlPane
FlatButton( FlatButton(
child: new Text("Yes"), child: new Text("Yes"),
onPressed: () { onPressed: () {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(entity.domain, "alarm_trigger", entity.entityId, null));
domain: entity.domain,
service: "alarm_trigger",
entityId: entity.entityId
);
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),

View File

@ -83,12 +83,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
_tempThrottleTimer = Timer(Duration(seconds: 2), () { _tempThrottleTimer = Timer(Duration(seconds: 2), () {
setState(() { setState(() {
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(entity.domain, "set_temperature", entity.entityId,{"temperature": "${_tmpTemperature.toStringAsFixed(1)}"}));
domain: entity.domain,
service: "set_temperature",
entityId: entity.entityId,
data: {"temperature": "${_tmpTemperature.toStringAsFixed(1)}"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
}); });
@ -106,12 +101,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
_targetTempThrottleTimer = Timer(Duration(seconds: 2), () { _targetTempThrottleTimer = Timer(Duration(seconds: 2), () {
setState(() { setState(() {
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(entity.domain, "set_temperature", entity.entityId,{"target_temp_high": "${_tmpTargetHigh.toStringAsFixed(1)}", "target_temp_low": "${_tmpTargetLow.toStringAsFixed(1)}"}));
domain: entity.domain,
service: "set_temperature",
entityId: entity.entityId,
data: {"target_temp_high": "${_tmpTargetHigh.toStringAsFixed(1)}", "target_temp_low": "${_tmpTargetLow.toStringAsFixed(1)}"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
}); });
@ -121,12 +111,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpTargetHumidity = value.roundToDouble(); _tmpTargetHumidity = value.roundToDouble();
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(entity.domain, "set_humidity", entity.entityId,{"humidity": "$_tmpTargetHumidity"}));
domain: entity.domain,
service: "set_humidity",
entityId: entity.entityId,
data: {"humidity": "$_tmpTargetHumidity"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -135,12 +120,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpHVACMode = value; _tmpHVACMode = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(entity.domain, "set_hvac_mode", entity.entityId,{"hvac_mode": "$_tmpHVACMode"}));
domain: entity.domain,
service: "set_hvac_mode",
entityId: entity.entityId,
data: {"hvac_mode": "$_tmpHVACMode"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -149,12 +129,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpSwingMode = value; _tmpSwingMode = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(entity.domain, "set_swing_mode", entity.entityId,{"swing_mode": "$_tmpSwingMode"}));
domain: entity.domain,
service: "set_swing_mode",
entityId: entity.entityId,
data: {"swing_mode": "$_tmpSwingMode"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -163,7 +138,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpFanMode = value; _tmpFanMode = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService(domain: entity.domain, service: "set_fan_mode", entityId: entity.entityId, data: {"fan_mode": "$_tmpFanMode"}); eventBus.fire(new ServiceCallEvent(entity.domain, "set_fan_mode", entity.entityId,{"fan_mode": "$_tmpFanMode"}));
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -172,7 +147,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpPresetMode = value; _tmpPresetMode = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService(domain: entity.domain, service: "set_preset_mode", entityId: entity.entityId, data: {"preset_mode": "$_tmpPresetMode"}); eventBus.fire(new ServiceCallEvent(entity.domain, "set_preset_mode", entity.entityId,{"preset_mode": "$_tmpPresetMode"}));
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -190,7 +165,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpAuxHeat = value; _tmpAuxHeat = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService(domain: entity.domain, service: "set_aux_heat", entityId: entity.entityId, data: {"aux_heat": "$_tmpAuxHeat"}); eventBus.fire(new ServiceCallEvent(entity.domain, "set_aux_heat", entity.entityId, {"aux_heat": "$_tmpAuxHeat"}));
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }

View File

@ -18,7 +18,7 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
setState(() { setState(() {
_tmpPosition = position.roundToDouble(); _tmpPosition = position.roundToDouble();
_changedHere = true; _changedHere = true;
ConnectionManager().callService(domain: entity.domain, service: "set_cover_position", entityId: entity.entityId, data: {"position": _tmpPosition.round()}); eventBus.fire(new ServiceCallEvent(entity.domain, "set_cover_position", entity.entityId,{"position": _tmpPosition.round()}));
}); });
} }
@ -26,7 +26,7 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
setState(() { setState(() {
_tmpTiltPosition = position.roundToDouble(); _tmpTiltPosition = position.roundToDouble();
_changedHere = true; _changedHere = true;
ConnectionManager().callService(domain: entity.domain, service: "set_cover_tilt_position", entityId: entity.entityId, data: {"tilt_position": _tmpTiltPosition.round()}); eventBus.fire(new ServiceCallEvent(entity.domain, "set_cover_tilt_position", entity.entityId,{"tilt_position": _tmpTiltPosition.round()}));
}); });
} }
@ -135,18 +135,18 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
class CoverTiltControlsWidget extends StatelessWidget { class CoverTiltControlsWidget extends StatelessWidget {
void _open(CoverEntity entity) { void _open(CoverEntity entity) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, service: "open_cover_tilt", entityId: entity.entityId); entity.domain, "open_cover_tilt", entity.entityId, null));
} }
void _close(CoverEntity entity) { void _close(CoverEntity entity) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, service: "close_cover_tilt", entityId: entity.entityId); entity.domain, "close_cover_tilt", entity.entityId, null));
} }
void _stop(CoverEntity entity) { void _stop(CoverEntity entity) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, service: "stop_cover_tilt", entityId: entity.entityId); entity.domain, "stop_cover_tilt", entity.entityId, null));
} }
@override @override

View File

@ -2,27 +2,18 @@ part of '../../../main.dart';
class CoverStateWidget extends StatelessWidget { class CoverStateWidget extends StatelessWidget {
void _open(CoverEntity entity) { void _open(CoverEntity entity) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "open_cover", entity.entityId, null));
service: "open_cover",
entityId: entity.entityId
);
} }
void _close(CoverEntity entity) { void _close(CoverEntity entity) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "close_cover", entity.entityId, null));
service: "close_cover",
entityId: entity.entityId
);
} }
void _stop(CoverEntity entity) { void _stop(CoverEntity entity) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "stop_cover", entity.entityId, null));
service: "stop_cover",
entityId: entity.entityId
);
} }
@override @override

View File

@ -35,7 +35,8 @@ class DateTimeEntity extends Entity {
return formattedState; return formattedState;
} }
void setNewState(Map newValue) { void setNewState(newValue) {
ConnectionManager().callService(domain: domain, service: "set_datetime", entityId: entityId, data: newValue); eventBus
.fire(new ServiceCallEvent(domain, "set_datetime", entityId, newValue));
} }
} }

View File

@ -153,7 +153,7 @@ class Entity {
domain = rawData["entity_id"].split(".")[0]; domain = rawData["entity_id"].split(".")[0];
entityId = rawData["entity_id"]; entityId = rawData["entity_id"];
deviceClass = attributes["device_class"]; deviceClass = attributes["device_class"];
state = rawData["state"] is bool ? (rawData["state"] ? EntityState.on : EntityState.off) : rawData["state"]; state = rawData["state"];
displayState = Entity.StateByDeviceClass["$deviceClass.$state"] ?? (state.toLowerCase() == 'unknown' ? '-' : state); displayState = Entity.StateByDeviceClass["$deviceClass.$state"] ?? (state.toLowerCase() == 'unknown' ? '-' : state);
_lastUpdated = DateTime.tryParse(rawData["last_updated"]); _lastUpdated = DateTime.tryParse(rawData["last_updated"]);
entityPicture = _getEntityPictureUrl(webHost); entityPicture = _getEntityPictureUrl(webHost);

View File

@ -17,7 +17,7 @@ class EntityPageLayout extends StatelessWidget {
showClose ? showClose ?
Container( Container(
color: Colors.blue[300], color: Colors.blue[300],
height: 40, height: 36,
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
@ -37,7 +37,7 @@ class EntityPageLayout extends StatelessWidget {
padding: EdgeInsets.all(0), padding: EdgeInsets.all(0),
icon: Icon(Icons.close), icon: Icon(Icons.close),
color: Colors.white, color: Colors.white,
iconSize: 36.0, iconSize: 30.0,
onPressed: () { onPressed: () {
eventBus.fire(ShowEntityPageEvent()); eventBus.fire(ShowEntityPageEvent());
}, },

View File

@ -32,17 +32,17 @@ class EntityWrapper {
void handleTap() { void handleTap() {
switch (uiAction.tapAction) { switch (uiAction.tapAction) {
case EntityUIAction.toggle: { case EntityUIAction.toggle: {
ConnectionManager().callService(domain: "homeassistant", service: "toggle", entityId: entity.entityId); eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entity.entityId, null));
break; break;
} }
case EntityUIAction.callService: { case EntityUIAction.callService: {
if (uiAction.tapService != null) { if (uiAction.tapService != null) {
ConnectionManager().callService( eventBus.fire(
domain: uiAction.tapService.split(".")[0], ServiceCallEvent(uiAction.tapService.split(".")[0],
service: uiAction.tapService.split(".")[1], uiAction.tapService.split(".")[1], null,
data: uiAction.tapServiceData uiAction.tapServiceData));
);
} }
break; break;
} }
@ -76,17 +76,17 @@ class EntityWrapper {
void handleHold() { void handleHold() {
switch (uiAction.holdAction) { switch (uiAction.holdAction) {
case EntityUIAction.toggle: { case EntityUIAction.toggle: {
ConnectionManager().callService(domain: "homeassistant", service: "toggle", entityId: entity.entityId); eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entity.entityId, null));
break; break;
} }
case EntityUIAction.callService: { case EntityUIAction.callService: {
if (uiAction.holdService != null) { if (uiAction.holdService != null) {
ConnectionManager().callService( eventBus.fire(
domain: uiAction.holdService.split(".")[0], ServiceCallEvent(uiAction.holdService.split(".")[0],
service: uiAction.holdService.split(".")[1], uiAction.holdService.split(".")[1], null,
data: uiAction.holdServiceData uiAction.holdServiceData));
);
} }
break; break;
} }

View File

@ -24,12 +24,9 @@ class _FanControlsWidgetState extends State<FanControlsWidget> {
setState(() { setState(() {
_tmpOscillate = oscillate; _tmpOscillate = oscillate;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: "fan", "fan", "oscillate", entity.entityId,
service: "oscillate", {"oscillating": oscillate}));
entityId: entity.entityId,
data: {"oscillating": oscillate}
);
}); });
} }
@ -37,12 +34,9 @@ class _FanControlsWidgetState extends State<FanControlsWidget> {
setState(() { setState(() {
_tmpDirectionForward = forward; _tmpDirectionForward = forward;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: "fan", "fan", "set_direction", entity.entityId,
service: "set_direction", {"direction": forward ? "forward" : "reverse"}));
entityId: entity.entityId,
data: {"direction": forward ? "forward" : "reverse"}
);
}); });
} }
@ -50,12 +44,9 @@ class _FanControlsWidgetState extends State<FanControlsWidget> {
setState(() { setState(() {
_tmpSpeed = value; _tmpSpeed = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: "fan", "fan", "set_speed", entity.entityId,
service: "set_speed", {"speed": value}));
entityId: entity.entityId,
data: {"speed": value}
);
}); });
} }

View File

@ -18,7 +18,7 @@ class FlatServiceButton extends StatelessWidget {
}) : super(key: key); }) : super(key: key);
void _setNewState() { void _setNewState() {
ConnectionManager().callService(domain: serviceDomain, service: serviceName, entityId: entityId); eventBus.fire(new ServiceCallEvent(serviceDomain, serviceName, entityId, null));
} }
@override @override

View File

@ -28,12 +28,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpBrightness = value.round(); _tmpBrightness = value.round();
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "turn_on", entity.entityId,
service: "turn_on", {"brightness": _tmpBrightness}));
entityId: entity.entityId,
data: {"brightness": _tmpBrightness}
);
}); });
} }
@ -41,12 +38,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpWhiteValue = value.round(); _tmpWhiteValue = value.round();
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "turn_on", entity.entityId,
service: "turn_on", {"white_value": _tmpWhiteValue}));
entityId: entity.entityId,
data: {"white_value": _tmpWhiteValue}
);
}); });
} }
@ -55,12 +49,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpColorTemp = value.round(); _tmpColorTemp = value.round();
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "turn_on", entity.entityId,
service: "turn_on", {"color_temp": _tmpColorTemp}));
entityId: entity.entityId,
data: {"color_temp": _tmpColorTemp}
);
}); });
} }
@ -68,12 +59,10 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpColor = color; _tmpColor = color;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( Logger.d( "HS Color: [${color.hue}, ${color.saturation}]");
domain: entity.domain, eventBus.fire(new ServiceCallEvent(
service: "turn_on", entity.domain, "turn_on", entity.entityId,
entityId: entity.entityId, {"hs_color": [color.hue, color.saturation*100]}));
data: {"hs_color": [color.hue, color.saturation*100]}
);
}); });
} }
@ -82,12 +71,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
_tmpEffect = value; _tmpEffect = value;
_changedHere = true; _changedHere = true;
if (_tmpEffect != null) { if (_tmpEffect != null) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "turn_on", entity.entityId,
service: "turn_on", {"effect": "$value"}));
entityId: entity.entityId,
data: {"effect": "$value"}
);
} }
}); });
} }
@ -241,6 +227,8 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
Widget _buildEffectControl(LightEntity entity) { Widget _buildEffectControl(LightEntity entity) {
if ((entity.supportEffect) && (entity.effectList != null)) { if ((entity.supportEffect) && (entity.effectList != null)) {
Logger.d("[LIGHT] entity effects: ${entity.effectList}");
Logger.d("[LIGHT] current effect: $_tmpEffect");
List<String> list = List.from(entity.effectList); List<String> list = List.from(entity.effectList);
if (_tmpEffect!= null && !list.contains(_tmpEffect)) { if (_tmpEffect!= null && !list.contains(_tmpEffect)) {
list.insert(0, _tmpEffect); list.insert(0, _tmpEffect);

View File

@ -7,11 +7,11 @@ class LockStateWidget extends StatelessWidget {
const LockStateWidget({Key key, this.assumedState: false}) : super(key: key); const LockStateWidget({Key key, this.assumedState: false}) : super(key: key);
void _lock(Entity entity) { void _lock(Entity entity) {
ConnectionManager().callService(domain: "lock", service: "lock", entityId: entity.entityId); eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null));
} }
void _unlock(Entity entity) { void _unlock(Entity entity) {
ConnectionManager().callService(domain: "lock", service: "unlock", entityId: entity.entityId); eventBus.fire(new ServiceCallEvent("lock", "unlock", entity.entityId, null));
} }
@override @override

View File

@ -56,12 +56,12 @@ class _MediaPlayerSeekBarState extends State<MediaPlayerSeekBar> {
color: Colors.orange, color: Colors.orange,
focusColor: Colors.white, focusColor: Colors.white,
onPressed: () { onPressed: () {
ConnectionManager().callService( eventBus.fire(ServiceCallEvent(
domain: "media_player", "media_player",
service: "media_seek", "media_seek",
entityId: entity.entityId, "${entity.entityId}",
data: {"seek_position": _savedPosition} {"seek_position": _savedPosition}
); ));
setState(() { setState(() {
_savedPosition = 0; _savedPosition = 0;
}); });
@ -103,12 +103,12 @@ class _MediaPlayerSeekBarState extends State<MediaPlayerSeekBar> {
_seekStarted = false; _seekStarted = false;
Timer(Duration(milliseconds: 500), () { Timer(Duration(milliseconds: 500), () {
if (!_seekStarted) { if (!_seekStarted) {
ConnectionManager().callService( eventBus.fire(ServiceCallEvent(
domain: "media_player", "media_player",
service: "media_seek", "media_seek",
entityId: entity.entityId, "${entity.entityId}",
data: {"seek_position": val} {"seek_position": val}
); ));
setState(() { setState(() {
_changedHere = true; _changedHere = true;
_currentPosition = val; _currentPosition = val;

View File

@ -118,28 +118,26 @@ class MediaPlayerPlaybackControls extends StatelessWidget {
void _setPower(MediaPlayerEntity entity) { void _setPower(MediaPlayerEntity entity) {
if (entity.state != EntityState.unavailable && entity.state != EntityState.unknown) {
if (entity.state == EntityState.off) { if (entity.state == EntityState.off) {
ConnectionManager().callService( Logger.d("${entity.entityId} turn_on");
domain: entity.domain, eventBus.fire(new ServiceCallEvent(
service: "turn_on", entity.domain, "turn_on", entity.entityId,
entityId: entity.entityId null));
);
} else { } else {
ConnectionManager().callService( Logger.d("${entity.entityId} turn_off");
domain: entity.domain, eventBus.fire(new ServiceCallEvent(
service: "turn_off", entity.domain, "turn_off", entity.entityId,
entityId: entity.entityId null));
);
} }
}
} }
void _callAction(MediaPlayerEntity entity, String action) { void _callAction(MediaPlayerEntity entity, String action) {
Logger.d("${entity.entityId} $action"); Logger.d("${entity.entityId} $action");
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: entity.domain, entity.domain, "$action", entity.entityId,
service: "$action", null));
entityId: entity.entityId
);
} }
@override @override
@ -266,50 +264,27 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
setState(() { setState(() {
_changedHere = true; _changedHere = true;
_newVolumeLevel = value; _newVolumeLevel = value;
ConnectionManager().callService( eventBus.fire(ServiceCallEvent("media_player", "volume_set", entityId, {"volume_level": value}));
domain: "media_player",
service: "volume_set",
entityId: entityId,
data: {"volume_level": value}
);
}); });
} }
void _setVolumeMute(bool isMuted, String entityId) { void _setVolumeMute(bool isMuted, String entityId) {
ConnectionManager().callService( eventBus.fire(ServiceCallEvent("media_player", "volume_mute", entityId, {"is_volume_muted": isMuted}));
domain: "media_player",
service: "volume_mute",
entityId: entityId,
data: {"is_volume_muted": isMuted}
);
} }
void _setVolumeUp(String entityId) { void _setVolumeUp(String entityId) {
ConnectionManager().callService( eventBus.fire(ServiceCallEvent("media_player", "volume_up", entityId, null));
domain: "media_player",
service: "volume_up",
entityId: entityId
);
} }
void _setVolumeDown(String entityId) { void _setVolumeDown(String entityId) {
ConnectionManager().callService( eventBus.fire(ServiceCallEvent("media_player", "volume_down", entityId, null));
domain: "media_player",
service: "volume_down",
entityId: entityId
);
} }
void _setSoundMode(String value, String entityId) { void _setSoundMode(String value, String entityId) {
setState(() { setState(() {
_newSoundMode = value; _newSoundMode = value;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(ServiceCallEvent("media_player", "select_sound_mode", entityId, {"sound_mode": "$value"}));
domain: "media_player",
service: "select_sound_mode",
entityId: entityId,
data: {"sound_mode": "$value"}
);
}); });
} }
@ -317,12 +292,7 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
setState(() { setState(() {
_newSource = source; _newSource = source;
_changedHere = true; _changedHere = true;
ConnectionManager().callService( eventBus.fire(ServiceCallEvent("media_player", "select_source", entityId, {"source": "$source"}));
domain: "media_player",
service: "select_source",
entityId: entityId,
data: {"source": "$source"}
);
}); });
} }
@ -461,10 +431,14 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
void _duplicateTo(entity) { void _duplicateTo(entity) {
HomeAssistant().savedPlayerPosition = entity.getActualPosition().toInt(); HomeAssistant().savedPlayerPosition = entity.getActualPosition().toInt();
Navigator.of(context).pushNamed("/play-media", arguments: { if (MediaQuery.of(context).size.width < Sizes.tabletMinWidth) {
Navigator.of(context).popAndPushNamed("/play-media", arguments: {"url": entity.attributes["media_content_id"], "type": entity.attributes["media_content_type"]});
} else {
Navigator.of(context).pushNamed("/play-media", arguments: {
"url": entity.attributes["media_content_id"], "url": entity.attributes["media_content_id"],
"type": entity.attributes["media_content_type"] "type": entity.attributes["media_content_type"]
}); });
}
} }
void _switchTo(entity) { void _switchTo(entity) {

View File

@ -11,12 +11,8 @@ class SelectStateWidget extends StatefulWidget {
class _SelectStateWidgetState extends State<SelectStateWidget> { class _SelectStateWidgetState extends State<SelectStateWidget> {
void setNewState(domain, entityId, newValue) { void setNewState(domain, entityId, newValue) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(domain, "select_option", entityId,
domain: domain, {"option": "$newValue"}));
service: "select_option",
entityId: entityId,
data: {"option": "$newValue"}
);
} }
@override @override

View File

@ -18,12 +18,8 @@ class _SliderControlsWidgetState extends State<SliderControlsWidget> {
_newValue = newValue; _newValue = newValue;
_changedHere = true; _changedHere = true;
}); });
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(domain, "set_value", entityId,
domain: domain, {"value": "${newValue.toString()}"}));
service: "set_value",
entityId: entityId,
data: {"value": "${newValue.toString()}"}
);
} }
@override @override

View File

@ -38,11 +38,8 @@ class _SwitchStateWidgetState extends State<SwitchStateWidget> {
} else { } else {
domain = entity.domain; domain = entity.domain;
} }
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(
domain: domain, domain, (newValue as bool) ? "turn_on" : "turn_off", entity.entityId, null));
service: (newValue as bool) ? "turn_on" : "turn_off",
entityId: entity.entityId
);
} }
@override @override

View File

@ -26,12 +26,8 @@ class _TextInputStateWidgetState extends State<TextInputStateWidget> {
void setNewState(newValue, domain, entityId) { void setNewState(newValue, domain, entityId) {
if (validate(newValue, _minLength, _maxLength)) { if (validate(newValue, _minLength, _maxLength)) {
ConnectionManager().callService( eventBus.fire(new ServiceCallEvent(domain, "set_value", entityId,
domain: domain, {"value": "$newValue"}));
service: "set_value",
entityId: entityId,
data: {"value": "$newValue"}
);
} else { } else {
setState(() { setState(() {
_tmpValue = _entityState; _tmpValue = _entityState;

View File

@ -197,7 +197,7 @@ class VacuumControls extends StatelessWidget {
domain: "vacuum", domain: "vacuum",
entityId: entity.entityId, entityId: entity.entityId,
service: "set_fan_speed", service: "set_fan_speed",
data: {"fan_speed": val} additionalServiceData: {"fan_speed": val}
) )
), ),
); );

View File

@ -106,20 +106,10 @@ class HomeAssistant {
}); });
} }
Future _getLovelace() { Future _getLovelace() async {
Completer completer = Completer(); await ConnectionManager().sendSocketMessage(type: "lovelace/config").then((data) => _rawLovelaceData = data).catchError((e) {
ConnectionManager().sendSocketMessage(type: "lovelace/config").then((data) { throw HAError("Error getting lovelace config: $e");
_rawLovelaceData = data;
completer.complete();
}).catchError((e) {
if ("$e" == "config_not_found") {
ConnectionManager().useLovelace = false;
completer.complete();
} else {
completer.completeError(HAError("Error getting lovelace config: $e"));
}
}); });
return completer.future;
} }
Future _getUserInfo() async { Future _getUserInfo() async {
@ -135,6 +125,7 @@ class HomeAssistant {
Future _getServices() async { Future _getServices() async {
await ConnectionManager().sendSocketMessage(type: "get_services").then((data) { await ConnectionManager().sendSocketMessage(type: "get_services").then((data) {
Logger.d("Got ${data.length} services"); Logger.d("Got ${data.length} services");
Logger.d("Media extractor: ${data["media_extractor"]}");
services = data; services = data;
}).catchError((e) { }).catchError((e) {
Logger.w("Can't get services: $e"); Logger.w("Can't get services: $e");
@ -189,17 +180,9 @@ class HomeAssistant {
if (rawView['badges'] != null && rawView['badges'] is List) { if (rawView['badges'] != null && rawView['badges'] is List) {
rawView['badges'].forEach((entity) { rawView['badges'].forEach((entity) {
if (entity is String) { if (entities.isExist(entity)) {
if (entities.isExist(entity)) { Entity e = entities.get(entity);
Entity e = entities.get(entity); view.badges.add(e);
view.badges.add(e);
}
} else {
String eId = '${entity['entity']}';
if (entities.isExist(eId)) {
Entity e = entities.get(eId);
view.badges.add(e);
}
} }
}); });
} }
@ -218,9 +201,6 @@ class HomeAssistant {
try { try {
//bool isThereCardOptionsInside = rawCard["card"] != null; //bool isThereCardOptionsInside = rawCard["card"] != null;
var rawCardInfo = rawCard["card"] ?? rawCard; var rawCardInfo = rawCard["card"] ?? rawCard;
if (rawCardInfo['state_filter'] != null) {
Logger.d("Hey!!!!!! We found a card with state filter: ${rawCardInfo['state_filter']}");
}
HACard card = HACard( HACard card = HACard(
id: "card", id: "card",
name: rawCardInfo["title"] ?? rawCardInfo["name"], name: rawCardInfo["title"] ?? rawCardInfo["name"],
@ -229,7 +209,7 @@ class HomeAssistant {
showName: rawCardInfo['show_name'] ?? true, showName: rawCardInfo['show_name'] ?? true,
showState: rawCardInfo['show_state'] ?? true, showState: rawCardInfo['show_state'] ?? true,
showEmpty: rawCardInfo['show_empty'] ?? true, showEmpty: rawCardInfo['show_empty'] ?? true,
stateFilter: (rawCard['state_filter'] ?? rawCardInfo['state_filter']) ?? [], stateFilter: rawCardInfo['state_filter'] ?? [],
states: rawCardInfo['states'], states: rawCardInfo['states'],
conditions: rawCard['conditions'] ?? [], conditions: rawCard['conditions'] ?? [],
content: rawCardInfo['content'], content: rawCardInfo['content'],

View File

@ -141,7 +141,7 @@ EventBus eventBus = new EventBus();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
const String appName = "HA Client"; const String appName = "HA Client";
const appVersionNumber = "0.7.2"; const appVersionNumber = "0.7.0";
const appVersionAdd = ""; const appVersionAdd = "";
const appVersion = "$appVersionNumber-$appVersionAdd"; const appVersion = "$appVersionNumber-$appVersionAdd";

View File

@ -189,13 +189,13 @@ class ConnectionManager {
//Logger.d("[Received] <== Request id ${data['id']} was successful"); //Logger.d("[Received] <== Request id ${data['id']} was successful");
_messageResolver["${data["id"]}"]?.complete(data["result"]); _messageResolver["${data["id"]}"]?.complete(data["result"]);
} else if (data["id"] != null) { } else if (data["id"] != null) {
Logger.e("[Received] <== Error received on request id ${data['id']}: ${data['error']}"); //Logger.e("[Received] <== Error received on request id ${data['id']}: ${data['error']}");
_messageResolver["${data["id"]}"]?.completeError("${data["error"]["code"]}"); _messageResolver["${data["id"]}"]?.completeError("${data['error']["message"]}");
} }
_messageResolver.remove("${data["id"]}"); _messageResolver.remove("${data["id"]}");
} else if (data["type"] == "event") { } else if (data["type"] == "event") {
if ((data["event"] != null) && (data["event"]["event_type"] == "state_changed")) { if ((data["event"] != null) && (data["event"]["event_type"] == "state_changed")) {
Logger.d("[Received] <== ${data['type']}.${data["event"]["event_type"]}: ${data["event"]["data"]["entity_id"]}"); //Logger.d("[Received] <== ${data['type']}.${data["event"]["event_type"]}: ${data["event"]["data"]["entity_id"]}");
onStateChangeCallback(data["event"]["data"]); onStateChangeCallback(data["event"]["data"]);
} else if (data["event"] != null) { } else if (data["event"] != null) {
Logger.w("Unhandled event type: ${data["event"]["event_type"]}"); Logger.w("Unhandled event type: ${data["event"]["event_type"]}");
@ -348,16 +348,14 @@ class ConnectionManager {
_currentMessageId += 1; _currentMessageId += 1;
} }
Future callService({@required String domain, @required String service, String entityId, Map data}) { Future callService({String domain, String service, String entityId, Map additionalServiceData}) {
eventBus.fire(NotifyServiceCallEvent(domain, service, entityId));
Logger.d("Service call: $domain.$service, $entityId, $data");
Completer completer = Completer(); Completer completer = Completer();
Map serviceData = {}; Map serviceData = {};
if (entityId != null) { if (entityId != null) {
serviceData["entity_id"] = entityId; serviceData["entity_id"] = entityId;
} }
if (data != null && data.isNotEmpty) { if (additionalServiceData != null && additionalServiceData.isNotEmpty) {
serviceData.addAll(data); serviceData.addAll(additionalServiceData);
} }
if (serviceData.isNotEmpty) if (serviceData.isNotEmpty)
sendHTTPPost( sendHTTPPost(
@ -368,7 +366,7 @@ class ConnectionManager {
else else
sendHTTPPost( sendHTTPPost(
endPoint: "/api/services/$domain/$service" endPoint: "/api/services/$domain/$service"
).then((data) => completer.complete(data)).catchError((e) => completer.completeError(HAError("${e["message"]}"))); ).then((data) => completer.complete(data)).catchError((e) => completer.completeError(HAError("${e["message"]}")));;
//return sendSocketMessage(type: "call_service", additionalData: {"domain": domain, "service": service}); //return sendSocketMessage(type: "call_service", additionalData: {"domain": domain, "service": service});
return completer.future; return completer.future;
} }
@ -409,11 +407,10 @@ class ConnectionManager {
headers: headers, headers: headers,
body: data body: data
).then((response) { ).then((response) {
Logger.d("[Received] <== HTTP ${response.statusCode}");
if (response.statusCode >= 200 && response.statusCode < 300 ) { if (response.statusCode >= 200 && response.statusCode < 300 ) {
Logger.d("[Received] <== HTTP ${response.statusCode}");
completer.complete(response.body); completer.complete(response.body);
} else { } else {
Logger.d("[Received] <== HTTP ${response.statusCode}: ${response.body}");
completer.completeError({"code": response.statusCode, "message": "${response.body}"}); completer.completeError({"code": response.statusCode, "message": "${response.body}"});
} }
}).catchError((e) { }).catchError((e) {

View File

@ -14,7 +14,7 @@ class LocationManager {
} }
final int defaultUpdateIntervalMinutes = 20; final int defaultUpdateIntervalMinutes = 20;
final String backgroundTaskId = "haclocationtask0"; final String backgroundTaskId = "haclocationtask4352";
final String backgroundTaskTag = "haclocation"; final String backgroundTaskTag = "haclocation";
Duration _updateInterval; Duration _updateInterval;
bool _isRunning; bool _isRunning;
@ -27,7 +27,6 @@ class LocationManager {
_isRunning = prefs.getBool("location-enabled") ?? false; _isRunning = prefs.getBool("location-enabled") ?? false;
if (_isRunning) { if (_isRunning) {
await _startLocationService(); await _startLocationService();
updateDeviceLocation(false);
} }
} }
@ -58,48 +57,27 @@ class LocationManager {
} }
_startLocationService() async { _startLocationService() async {
Logger.d("Scheduling location update for every ${_updateInterval
.inMinutes} minutes...");
String webhookId = ConnectionManager().webhookId; String webhookId = ConnectionManager().webhookId;
String httpWebHost = ConnectionManager().httpWebHost; String httpWebHost = ConnectionManager().httpWebHost;
if (webhookId != null && webhookId.isNotEmpty) { if (webhookId != null && webhookId.isNotEmpty) {
Duration interval; await workManager.Workmanager.registerPeriodicTask(
int delayFactor; backgroundTaskId,
int taskCount; "haClientLocationTracking",
Logger.d("Starting location update for every ${_updateInterval tag: backgroundTaskTag,
.inMinutes} minutes..."); inputData: {
if (_updateInterval.inMinutes == 10) { "webhookId": webhookId,
interval = Duration(minutes: 20); "httpWebHost": httpWebHost
taskCount = 2; },
delayFactor = 10; frequency: _updateInterval,
} else if (_updateInterval.inMinutes == 5) { existingWorkPolicy: workManager.ExistingWorkPolicy.keep,
interval = Duration(minutes: 15); backoffPolicy: workManager.BackoffPolicy.linear,
taskCount = 3; backoffPolicyDelay: _updateInterval,
delayFactor = 5; constraints: workManager.Constraints(
} else { networkType: workManager.NetworkType.connected
interval = _updateInterval; )
taskCount = 1; );
delayFactor = 0;
}
for (int i = 1; i <= taskCount; i++) {
int delay = i*delayFactor;
Logger.d("Scheduling location update task #$i for every ${interval.inMinutes} minutes in $delay minutes...");
await workManager.Workmanager.registerPeriodicTask(
"$backgroundTaskId$n",
"haClientLocationTracking",
tag: backgroundTaskTag,
inputData: {
"webhookId": webhookId,
"httpWebHost": httpWebHost
},
frequency: interval,
initialDelay: Duration(minutes: delay),
existingWorkPolicy: workManager.ExistingWorkPolicy.keep,
backoffPolicy: workManager.BackoffPolicy.linear,
backoffPolicyDelay: interval,
constraints: workManager.Constraints(
networkType: workManager.NetworkType.connected
)
);
}
} }
} }
@ -108,46 +86,33 @@ class LocationManager {
await workManager.Workmanager.cancelByTag(backgroundTaskTag); await workManager.Workmanager.cancelByTag(backgroundTaskTag);
} }
updateDeviceLocation(bool force) async { updateDeviceLocation() async {
if (!force && !_isRunning) { if (ConnectionManager().webhookId != null &&
Logger.d("[Foreground location] Not enabled. Aborting."); ConnectionManager().webhookId.isNotEmpty) {
return; String url = "${ConnectionManager()
} .httpWebHost}/api/webhook/${ConnectionManager().webhookId}";
Logger.d("[Foreground location] Started"); Map<String, String> headers = {};
//Logger.d("[Foreground location] Forcing Android location manager..."); Logger.d("[Location] Getting device location...");
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true; Position location = await Geolocator().getCurrentPosition(
var battery = Battery(); desiredAccuracy: LocationAccuracy.medium);
String webhookId = ConnectionManager().webhookId; Logger.d("[Location] Got location: ${location.latitude} ${location
String httpWebHost = ConnectionManager().httpWebHost; .longitude}. Sending home...");
if (webhookId != null && webhookId.isNotEmpty) { int battery = await Battery().batteryLevel;
Logger.d("[Foreground location] Getting battery level..."); var data = {
int batteryLevel = await battery.batteryLevel; "type": "update_location",
Logger.d("[Foreground location] Getting device location..."); "data": {
Position position = await geolocator.getCurrentPosition( "gps": [location.latitude, location.longitude],
desiredAccuracy: LocationAccuracy.high, "gps_accuracy": location.accuracy,
locationPermissionLevel: GeolocationPermission.locationAlways "battery": battery
); }
if (position != null) { };
Logger.d("[Foreground location] Location: ${position.latitude} ${position.longitude}. Accuracy: ${position.accuracy}. (${position.timestamp})"); headers["Content-Type"] = "application/json";
String url = "$httpWebHost/api/webhook/$webhookId"; await http.post(
Map data = {
"type": "update_location",
"data": {
"gps": [position.latitude, position.longitude],
"gps_accuracy": position.accuracy,
"battery": batteryLevel ?? 100
}
};
Logger.d("[Foreground location] Sending data home...");
var response = await http.post(
url, url,
headers: {"Content-Type": "application/json"}, headers: headers,
body: json.encode(data) body: json.encode(data)
); );
Logger.d("[Foreground location] Got HTTP ${response.statusCode}"); Logger.d("[Location] ...done.");
} else {
Logger.d("[Foreground location] No location. Aborting.");
}
} }
} }
@ -156,7 +121,6 @@ class LocationManager {
void updateDeviceLocationIsolate() { void updateDeviceLocationIsolate() {
workManager.Workmanager.executeTask((backgroundTask, data) { workManager.Workmanager.executeTask((backgroundTask, data) {
//print("[Background $backgroundTask] Started"); //print("[Background $backgroundTask] Started");
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
var battery = Battery(); var battery = Battery();
int batteryLevel = 100; int batteryLevel = 100;
String webhookId = data["webhookId"]; String webhookId = data["webhookId"];
@ -177,7 +141,7 @@ void updateDeviceLocationIsolate() {
//print("[Background $backgroundTask] Getting battery level..."); //print("[Background $backgroundTask] Getting battery level...");
battery.batteryLevel.then((val) => data["data"]["battery"] = val).whenComplete((){ battery.batteryLevel.then((val) => data["data"]["battery"] = val).whenComplete((){
//print("[Background $backgroundTask] Getting device location..."); //print("[Background $backgroundTask] Getting device location...");
geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways).then((location) { Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
//print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}"); //print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}");
if (location != null) { if (location != null) {
data["data"]["gps"] = [location.latitude, location.longitude]; data["data"]["gps"] = [location.latitude, location.longitude];
@ -191,7 +155,7 @@ void updateDeviceLocationIsolate() {
} }
}).catchError((e) { }).catchError((e) {
//print("[Background $backgroundTask] Error getting current location: ${e.toString()}. Trying last known..."); //print("[Background $backgroundTask] Error getting current location: ${e.toString()}. Trying last known...");
geolocator.getLastKnownPosition(desiredAccuracy: LocationAccuracy.medium).then((location){ Geolocator().getLastKnownPosition(desiredAccuracy: LocationAccuracy.medium).then((location){
//print("[Background $backgroundTask] Got last known location: ${location.latitude} ${location.longitude}"); //print("[Background $backgroundTask] Got last known location: ${location.latitude} ${location.longitude}");
if (location != null) { if (location != null) {
data["data"]["gps"] = [location.latitude, location.longitude]; data["data"]["gps"] = [location.latitude, location.longitude];

View File

@ -45,7 +45,7 @@ class MobileAppIntegrationManager {
positiveText: "Restart now", positiveText: "Restart now",
negativeText: "Later", negativeText: "Later",
onPositive: () { onPositive: () {
ConnectionManager().callService(domain: "homeassistant", service: "restart"); ConnectionManager().callService(domain: "homeassistant", service: "restart", entityId: null);
}, },
)); ));
}); });

View File

@ -29,9 +29,6 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
setState(() { setState(() {
_locationTrackingEnabled = prefs.getBool("location-enabled") ?? false; _locationTrackingEnabled = prefs.getBool("location-enabled") ?? false;
_locationInterval = prefs.getInt("location-interval") ?? LocationManager().defaultUpdateIntervalMinutes; _locationInterval = prefs.getInt("location-interval") ?? LocationManager().defaultUpdateIntervalMinutes;
if (_locationInterval % 5 != 0) {
_locationInterval = 5 * (_locationInterval ~/ 5);
}
}); });
}); });
} }
@ -39,15 +36,15 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
void incLocationInterval() { void incLocationInterval() {
if (_locationInterval < 720) { if (_locationInterval < 720) {
setState(() { setState(() {
_locationInterval = _locationInterval + 5; _locationInterval = _locationInterval + 1;
}); });
} }
} }
void decLocationInterval() { void decLocationInterval() {
if (_locationInterval > 5) { if (_locationInterval > 1) {
setState(() { setState(() {
_locationInterval = _locationInterval - 5; _locationInterval = _locationInterval - 1;
}); });
} }
} }
@ -59,7 +56,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
positiveText: "Sure. Make it so", positiveText: "Sure. Make it so",
negativeText: "What?? No!", negativeText: "What?? No!",
onPositive: () { onPositive: () {
ConnectionManager().callService(domain: "homeassistant", service: "restart"); ConnectionManager().callService(domain: "homeassistant", service: "restart", entityId: null);
}, },
)); ));
} }
@ -71,7 +68,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
positiveText: "Sure. Make it so", positiveText: "Sure. Make it so",
negativeText: "What?? No!", negativeText: "What?? No!",
onPositive: () { onPositive: () {
ConnectionManager().callService(domain: "homeassistant", service: "stop"); ConnectionManager().callService(domain: "homeassistant", service: "stop", entityId: null);
}, },
)); ));
} }
@ -94,7 +91,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
_switchLocationTrackingState(bool state) async { _switchLocationTrackingState(bool state) async {
if (state) { if (state) {
await LocationManager().updateDeviceLocation(true); await LocationManager().updateDeviceLocation();
} }
await LocationManager().setSettings(_locationTrackingEnabled, _locationInterval); await LocationManager().setSettings(_locationTrackingEnabled, _locationInterval);
setState(() { setState(() {

View File

@ -26,7 +26,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
bool _showLoginButton = false; bool _showLoginButton = false;
bool _preventAppRefresh = false; bool _preventAppRefresh = false;
String _savedSharedText; String _savedSharedText;
Entity _entityToShow; String _entityToShow;
@override @override
void initState() { void initState() {
@ -122,7 +122,6 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
_showInfoBottomBar(progress: true,); _showInfoBottomBar(progress: true,);
ConnectionManager().init(loadSettings: false, forceReconnect: false).then((_){ ConnectionManager().init(loadSettings: false, forceReconnect: false).then((_){
_fetchData(); _fetchData();
LocationManager().updateDeviceLocation(false);
//StartupUserMessagesManager().checkMessagesToShow(); //StartupUserMessagesManager().checkMessagesToShow();
}, onError: (e) { }, onError: (e) {
_setErrorState(e); _setErrorState(e);
@ -143,9 +142,6 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
_viewsTabController = TabController(vsync: this, length: currentViewCount); _viewsTabController = TabController(vsync: this, length: currentViewCount);
_previousViewCount = currentViewCount; _previousViewCount = currentViewCount;
} }
if (_entityToShow != null) {
_entityToShow = HomeAssistant().entities.get(_entityToShow.entityId);
}
}).catchError((e) { }).catchError((e) {
if (e is HAError) { if (e is HAError) {
_setErrorState(e); _setErrorState(e);
@ -222,8 +218,9 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
} }
if (_serviceCallSubscription == null) { if (_serviceCallSubscription == null) {
_serviceCallSubscription = _serviceCallSubscription =
eventBus.on<NotifyServiceCallEvent>().listen((event) { eventBus.on<ServiceCallEvent>().listen((event) {
_notifyServiceCalled(event.domain, event.service, event.entityId); _callService(event.domain, event.service, event.entityId,
event.additionalParams);
}); });
} }
@ -321,28 +318,27 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
); );
} }
void _notifyServiceCalled(String domain, String service, String entityId) { //TODO remove this shit.... maybe
void _callService(String domain, String service, String entityId, Map additionalParams) {
_showInfoBottomBar( _showInfoBottomBar(
message: "Calling $domain.$service", message: "Calling $domain.$service",
duration: Duration(seconds: 4) duration: Duration(seconds: 3)
); );
ConnectionManager().callService(domain: domain, service: service, entityId: entityId, additionalServiceData: additionalParams).catchError((e) => _setErrorState(e));
} }
void _showEntityPage(String entityId) { void _showEntityPage(String entityId) {
setState(() { setState(() {
_entityToShow = HomeAssistant().entities.get(entityId); _entityToShow = entityId;
if (_entityToShow != null) {
_mainScrollController?.jumpTo(0);
}
}); });
/*if (_entityToShow!= null && MediaQuery.of(context).size.width < Sizes.tabletMinWidth) { if (_entityToShow!= null && MediaQuery.of(context).size.width < Sizes.tabletMinWidth) {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => EntityViewPage(entityId: entityId), builder: (context) => EntityViewPage(entityId: entityId),
) )
); );
}*/ }
} }
void _showPage(String path, bool goBackFirst) { void _showPage(String path, bool goBackFirst) {
@ -372,7 +368,12 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
menuItems.add( menuItems.add(
UserAccountsDrawerHeader( UserAccountsDrawerHeader(
accountName: Text(HomeAssistant().userName), accountName: Text(HomeAssistant().userName),
accountEmail: Text(HomeAssistant().locationName ?? ""), accountEmail: Text(ConnectionManager().displayHostname ?? "Not configured"),
onDetailsPressed: () {
Launcher.launchURLInCustomTab(
url: "${ConnectionManager().httpWebHost}/profile?external_auth=1"
);
},
currentAccountPicture: CircleAvatar( currentAccountPicture: CircleAvatar(
child: Text( child: Text(
HomeAssistant().userAvatarText, HomeAssistant().userAvatarText,
@ -635,7 +636,6 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
} }
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final ScrollController _mainScrollController = ScrollController();
Widget _buildScaffoldBody(bool empty) { Widget _buildScaffoldBody(bool empty) {
List<PopupMenuItem<String>> serviceMenuItems = []; List<PopupMenuItem<String>> serviceMenuItems = [];
@ -730,6 +730,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
} }
} else { } else {
if (_entityToShow != null && MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) { if (_entityToShow != null && MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) {
Entity entity = HomeAssistant().entities.get(_entityToShow);
mainScrollBody = Flex( mainScrollBody = Flex(
direction: Axis.horizontal, direction: Axis.horizontal,
children: <Widget>[ children: <Widget>[
@ -742,13 +743,12 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
), ),
ConstrainedBox( ConstrainedBox(
constraints: BoxConstraints.tightFor(width: Sizes.entityPageMaxWidth), constraints: BoxConstraints.tightFor(width: Sizes.entityPageMaxWidth),
child: EntityPageLayout(entity: _entityToShow, showClose: true,), child: EntityPageLayout(entity: entity, showClose: true,),
) )
], ],
); );
} else if (_entityToShow != null) {
mainScrollBody = EntityPageLayout(entity: _entityToShow, showClose: true,);
} else { } else {
_entityToShow = null;
mainScrollBody = HomeAssistant().buildViews(context, _viewsTabController); mainScrollBody = HomeAssistant().buildViews(context, _viewsTabController);
} }
} }
@ -804,7 +804,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
_scaffoldKey.currentState.openDrawer(); _scaffoldKey.currentState.openDrawer();
}, },
), ),
bottom: (empty || _entityToShow != null) ? null : TabBar( bottom: empty ? null : TabBar(
controller: _viewsTabController, controller: _viewsTabController,
tabs: buildUIViewTabs(), tabs: buildUIViewTabs(),
isScrollable: true, isScrollable: true,
@ -813,8 +813,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
]; ];
}, },
body: mainScrollBody, body: mainScrollBody
controller: _mainScrollController,
); );
} }
@ -880,22 +879,12 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
body: _buildScaffoldBody(true) body: _buildScaffoldBody(true)
); );
} else { } else {
return WillPopScope( return Scaffold(
child: Scaffold( key: _scaffoldKey,
key: _scaffoldKey, drawer: _buildAppDrawer(),
drawer: _buildAppDrawer(), primary: false,
primary: false, bottomNavigationBar: bottomBar,
bottomNavigationBar: bottomBar, body: _buildScaffoldBody(false)
body: _buildScaffoldBody(false)
),
onWillPop: () {
if (_entityToShow != null) {
eventBus.fire(ShowEntityPageEvent());
return Future.value(false);
} else {
return Future.value(true);
}
},
); );
} }
} }

View File

@ -90,20 +90,16 @@ class _PlayMediaPageState extends State<PlayMediaPage> {
Navigator.pop(context); Navigator.pop(context);
ConnectionManager().callService( ConnectionManager().callService(
domain: serviceDomain, domain: serviceDomain,
service: "play_media",
entityId: entity.entityId, entityId: entity.entityId,
data: { service: "play_media",
"media_content_id": _mediaUrl, additionalServiceData: {
"media_content_type": _contentType "media_content_id": _mediaUrl,
} "media_content_type": _contentType
}
); );
HomeAssistant().sendToPlayerId = entity.entityId; HomeAssistant().sendToPlayerId = entity.entityId;
if (HomeAssistant().sendFromPlayerId != null && HomeAssistant().sendFromPlayerId != HomeAssistant().sendToPlayerId) { if (HomeAssistant().sendFromPlayerId != null && HomeAssistant().sendFromPlayerId != HomeAssistant().sendToPlayerId) {
ConnectionManager().callService( eventBus.fire(ServiceCallEvent(HomeAssistant().sendFromPlayerId.split(".")[0], "turn_off", HomeAssistant().sendFromPlayerId, null));
domain: HomeAssistant().sendFromPlayerId.split(".")[0],
service: "turn_off",
entityId: HomeAssistant().sendFromPlayerId
);
HomeAssistant().sendFromPlayerId = null; HomeAssistant().sendFromPlayerId = null;
} }
eventBus.fire(ShowEntityPageEvent(entity: entity)); eventBus.fire(ShowEntityPageEvent(entity: entity));

View File

@ -24,7 +24,7 @@ class _WhatsNewPageState extends State<WhatsNewPage> {
error = ""; error = "";
}); });
http.Response response; http.Response response;
response = await http.get("http://ha-client.homemade.systems/service/whats_new_0.7.0.md"); response = await http.get("http://ha-client.homemade.systems/service/whats_new_$appVersionNumber.md");
if (response.statusCode == 200) { if (response.statusCode == 200) {
setState(() { setState(() {
data = response.body; data = response.body;

View File

@ -33,12 +33,13 @@ class StartAuthEvent {
StartAuthEvent(this.oauthUrl, this.showButton); StartAuthEvent(this.oauthUrl, this.showButton);
} }
class NotifyServiceCallEvent { class ServiceCallEvent {
String domain; String domain;
String service; String service;
String entityId; String entityId;
Map<String, dynamic> additionalParams;
NotifyServiceCallEvent(this.domain, this.service, this.entityId); ServiceCallEvent(this.domain, this.service, this.entityId, this.additionalParams);
} }
class ShowPopupDialogEvent { class ShowPopupDialogEvent {

View File

@ -1,8 +1,7 @@
name: hass_client name: hass_client
description: Home Assistant Android Client description: Home Assistant Android Client
version: 0.7.2+720 version: 0.7.1+713
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.0.0-dev.68.0 <3.0.0"
@ -26,7 +25,7 @@ dependencies:
flutter_secure_storage: ^3.3.1+1 flutter_secure_storage: ^3.3.1+1
device_info: ^0.4.0+3 device_info: ^0.4.0+3
flutter_local_notifications: ^0.8.4 flutter_local_notifications: ^0.8.4
geolocator: ^5.1.5 geolocator: ^5.1.4+2
workmanager: ^0.1.3 workmanager: ^0.1.3
battery: ^0.3.1+1 battery: ^0.3.1+1
share: share: