Show entity page on main page

This commit is contained in:
Yegor Vialov 2019-10-28 17:59:47 +00:00
parent 327f623ef7
commit b34cc97080
24 changed files with 186 additions and 147 deletions

View File

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

View File

@ -83,7 +83,12 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
_tempThrottleTimer = Timer(Duration(seconds: 2), () { _tempThrottleTimer = Timer(Duration(seconds: 2), () {
setState(() { setState(() {
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_temperature", entity.entityId,{"temperature": "${_tmpTemperature.toStringAsFixed(1)}"})); ConnectionManager().callService(
entity.domain,
"set_temperature",
entity.entityId,
{"temperature": "${_tmpTemperature.toStringAsFixed(1)}"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
}); });
@ -101,7 +106,12 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
_targetTempThrottleTimer = Timer(Duration(seconds: 2), () { _targetTempThrottleTimer = Timer(Duration(seconds: 2), () {
setState(() { setState(() {
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_temperature", entity.entityId,{"target_temp_high": "${_tmpTargetHigh.toStringAsFixed(1)}", "target_temp_low": "${_tmpTargetLow.toStringAsFixed(1)}"})); ConnectionManager().callService(
entity.domain,
"set_temperature",
entity.entityId,
{"target_temp_high": "${_tmpTargetHigh.toStringAsFixed(1)}", "target_temp_low": "${_tmpTargetLow.toStringAsFixed(1)}"}
);
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
}); });
@ -111,7 +121,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpTargetHumidity = value.roundToDouble(); _tmpTargetHumidity = value.roundToDouble();
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_humidity", entity.entityId,{"humidity": "$_tmpTargetHumidity"})); ConnectionManager().callService(entity.domain, "set_humidity", entity.entityId, {"humidity": "$_tmpTargetHumidity"});
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -120,7 +130,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpHVACMode = value; _tmpHVACMode = value;
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_hvac_mode", entity.entityId,{"hvac_mode": "$_tmpHVACMode"})); ConnectionManager().callService(entity.domain, "set_hvac_mode", entity.entityId, {"hvac_mode": "$_tmpHVACMode"});
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -129,7 +139,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpSwingMode = value; _tmpSwingMode = value;
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_swing_mode", entity.entityId,{"swing_mode": "$_tmpSwingMode"})); ConnectionManager().callService(entity.domain, "set_swing_mode", entity.entityId, {"swing_mode": "$_tmpSwingMode"});
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -138,7 +148,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpFanMode = value; _tmpFanMode = value;
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_fan_mode", entity.entityId,{"fan_mode": "$_tmpFanMode"})); ConnectionManager().callService(entity.domain, "set_fan_mode", entity.entityId, {"fan_mode": "$_tmpFanMode"});
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -147,7 +157,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpPresetMode = value; _tmpPresetMode = value;
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_preset_mode", entity.entityId,{"preset_mode": "$_tmpPresetMode"})); ConnectionManager().callService(entity.domain, "set_preset_mode", entity.entityId, {"preset_mode": "$_tmpPresetMode"});
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -165,7 +175,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() { setState(() {
_tmpAuxHeat = value; _tmpAuxHeat = value;
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_aux_heat", entity.entityId, {"aux_heat": "$_tmpAuxHeat"})); ConnectionManager().callService(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;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_cover_position", entity.entityId,{"position": _tmpPosition.round()})); ConnectionManager().callService(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;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_cover_tilt_position", entity.entityId,{"tilt_position": _tmpTiltPosition.round()})); ConnectionManager().callService(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) {
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "open_cover_tilt", entity.entityId, null)); entity.domain, "open_cover_tilt", entity.entityId, null);
} }
void _close(CoverEntity entity) { void _close(CoverEntity entity) {
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "close_cover_tilt", entity.entityId, null)); entity.domain, "close_cover_tilt", entity.entityId, null);
} }
void _stop(CoverEntity entity) { void _stop(CoverEntity entity) {
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "stop_cover_tilt", entity.entityId, null)); entity.domain, "stop_cover_tilt", entity.entityId, null);
} }
@override @override

View File

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

View File

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

View File

@ -17,7 +17,7 @@ class EntityPageLayout extends StatelessWidget {
showClose ? showClose ?
Container( Container(
color: Colors.blue[300], color: Colors.blue[300],
height: 36, height: 40,
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: 30.0, iconSize: 36.0,
onPressed: () { onPressed: () {
eventBus.fire(ShowEntityPageEvent()); eventBus.fire(ShowEntityPageEvent());
}, },

View File

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

View File

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

View File

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

View File

@ -28,9 +28,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpBrightness = value.round(); _tmpBrightness = value.round();
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId, entity.domain, "turn_on", entity.entityId,
{"brightness": _tmpBrightness})); {"brightness": _tmpBrightness});
}); });
} }
@ -38,9 +38,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpWhiteValue = value.round(); _tmpWhiteValue = value.round();
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId, entity.domain, "turn_on", entity.entityId,
{"white_value": _tmpWhiteValue})); {"white_value": _tmpWhiteValue});
}); });
} }
@ -49,9 +49,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() { setState(() {
_tmpColorTemp = value.round(); _tmpColorTemp = value.round();
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId, entity.domain, "turn_on", entity.entityId,
{"color_temp": _tmpColorTemp})); {"color_temp": _tmpColorTemp});
}); });
} }
@ -60,9 +60,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
_tmpColor = color; _tmpColor = color;
_changedHere = true; _changedHere = true;
Logger.d( "HS Color: [${color.hue}, ${color.saturation}]"); Logger.d( "HS Color: [${color.hue}, ${color.saturation}]");
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId, entity.domain, "turn_on", entity.entityId,
{"hs_color": [color.hue, color.saturation*100]})); {"hs_color": [color.hue, color.saturation*100]});
}); });
} }
@ -71,9 +71,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
_tmpEffect = value; _tmpEffect = value;
_changedHere = true; _changedHere = true;
if (_tmpEffect != null) { if (_tmpEffect != null) {
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId, entity.domain, "turn_on", entity.entityId,
{"effect": "$value"})); {"effect": "$value"});
} }
}); });
} }

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) {
eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null)); ConnectionManager().callService("lock", "lock", entity.entityId, null);
} }
void _unlock(Entity entity) { void _unlock(Entity entity) {
eventBus.fire(new ServiceCallEvent("lock", "unlock", entity.entityId, null)); ConnectionManager().callService("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: () {
eventBus.fire(ServiceCallEvent( ConnectionManager().callService(
"media_player", "media_player",
"media_seek", "media_seek",
"${entity.entityId}", "${entity.entityId}",
{"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) {
eventBus.fire(ServiceCallEvent( ConnectionManager().callService(
"media_player", "media_player",
"media_seek", "media_seek",
"${entity.entityId}", "${entity.entityId}",
{"seek_position": val} {"seek_position": val}
)); );
setState(() { setState(() {
_changedHere = true; _changedHere = true;
_currentPosition = val; _currentPosition = val;

View File

@ -121,23 +121,23 @@ class MediaPlayerPlaybackControls extends StatelessWidget {
if (entity.state != EntityState.unavailable && entity.state != EntityState.unknown) { if (entity.state != EntityState.unavailable && entity.state != EntityState.unknown) {
if (entity.state == EntityState.off) { if (entity.state == EntityState.off) {
Logger.d("${entity.entityId} turn_on"); Logger.d("${entity.entityId} turn_on");
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId, entity.domain, "turn_on", entity.entityId,
null)); null);
} else { } else {
Logger.d("${entity.entityId} turn_off"); Logger.d("${entity.entityId} turn_off");
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "turn_off", entity.entityId, entity.domain, "turn_off", entity.entityId,
null)); null);
} }
} }
} }
void _callAction(MediaPlayerEntity entity, String action) { void _callAction(MediaPlayerEntity entity, String action) {
Logger.d("${entity.entityId} $action"); Logger.d("${entity.entityId} $action");
eventBus.fire(new ServiceCallEvent( ConnectionManager().callService(
entity.domain, "$action", entity.entityId, entity.domain, "$action", entity.entityId,
null)); null);
} }
@override @override
@ -264,27 +264,27 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
setState(() { setState(() {
_changedHere = true; _changedHere = true;
_newVolumeLevel = value; _newVolumeLevel = value;
eventBus.fire(ServiceCallEvent("media_player", "volume_set", entityId, {"volume_level": value})); ConnectionManager().callService("media_player", "volume_set", entityId, {"volume_level": value});
}); });
} }
void _setVolumeMute(bool isMuted, String entityId) { void _setVolumeMute(bool isMuted, String entityId) {
eventBus.fire(ServiceCallEvent("media_player", "volume_mute", entityId, {"is_volume_muted": isMuted})); ConnectionManager().callService("media_player", "volume_mute", entityId, {"is_volume_muted": isMuted});
} }
void _setVolumeUp(String entityId) { void _setVolumeUp(String entityId) {
eventBus.fire(ServiceCallEvent("media_player", "volume_up", entityId, null)); ConnectionManager().callService("media_player", "volume_up", entityId, null);
} }
void _setVolumeDown(String entityId) { void _setVolumeDown(String entityId) {
eventBus.fire(ServiceCallEvent("media_player", "volume_down", entityId, null)); ConnectionManager().callService("media_player", "volume_down", entityId, null);
} }
void _setSoundMode(String value, String entityId) { void _setSoundMode(String value, String entityId) {
setState(() { setState(() {
_newSoundMode = value; _newSoundMode = value;
_changedHere = true; _changedHere = true;
eventBus.fire(ServiceCallEvent("media_player", "select_sound_mode", entityId, {"sound_mode": "$value"})); ConnectionManager().callService("media_player", "select_sound_mode", entityId, {"sound_mode": "$value"});
}); });
} }
@ -292,7 +292,7 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
setState(() { setState(() {
_newSource = source; _newSource = source;
_changedHere = true; _changedHere = true;
eventBus.fire(ServiceCallEvent("media_player", "select_source", entityId, {"source": "$source"})); ConnectionManager().callService("media_player", "select_source", entityId, {"source": "$source"});
}); });
} }

View File

@ -11,8 +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) {
eventBus.fire(new ServiceCallEvent(domain, "select_option", entityId, ConnectionManager().callService(domain, "select_option", entityId,
{"option": "$newValue"})); {"option": "$newValue"});
} }
@override @override

View File

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

View File

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

View File

@ -26,8 +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)) {
eventBus.fire(new ServiceCallEvent(domain, "set_value", entityId, ConnectionManager().callService(domain, "set_value", entityId,
{"value": "$newValue"})); {"value": "$newValue"});
} else { } else {
setState(() { setState(() {
_tmpValue = _entityState; _tmpValue = _entityState;

View File

@ -77,9 +77,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "start" "start",
null
), ),
) )
); );
@ -90,9 +91,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play-pause")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play-pause")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "start_pause" "start_pause",
null
), ),
) )
); );
@ -102,9 +104,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:pause")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:pause")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "pause" "pause",
null
), ),
) )
); );
@ -115,9 +118,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:stop")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:stop")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "stop" "stop",
null
), ),
) )
); );
@ -128,9 +132,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:broom")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:broom")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "clean_spot" "clean_spot",
null
), ),
) )
); );
@ -141,9 +146,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:map-marker")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:map-marker")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "locate" "locate",
null
), ),
) )
); );
@ -154,9 +160,10 @@ class VacuumControls extends StatelessWidget {
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:home-map-marker")), icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:home-map-marker")),
iconSize: iconSize, iconSize: iconSize,
onPressed: () => ConnectionManager().callService( onPressed: () => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "return_to_base" "return_to_base",
null
), ),
) )
); );
@ -194,10 +201,10 @@ class VacuumControls extends StatelessWidget {
options: entity.fanSpeedList, options: entity.fanSpeedList,
value: entity.fanSpeed, value: entity.fanSpeed,
onChange: (val) => ConnectionManager().callService( onChange: (val) => ConnectionManager().callService(
domain: "vacuum", "vacuum",
entityId: entity.entityId, entity.entityId,
service: "set_fan_speed", "set_fan_speed",
additionalServiceData: {"fan_speed": val} {"fan_speed": val}
) )
), ),
); );

View File

@ -348,14 +348,15 @@ class ConnectionManager {
_currentMessageId += 1; _currentMessageId += 1;
} }
Future callService({String domain, String service, String entityId, Map additionalServiceData}) { Future callService(String domain, String service, String entityId, Map serviceData) {
eventBus.fire(NotifyServiceCallEvent(domain, service, entityId));
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 (additionalServiceData != null && additionalServiceData.isNotEmpty) { if (serviceData != null && serviceData.isNotEmpty) {
serviceData.addAll(additionalServiceData); serviceData.addAll(serviceData);
} }
if (serviceData.isNotEmpty) if (serviceData.isNotEmpty)
sendHTTPPost( sendHTTPPost(

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", entityId: null); ConnectionManager().callService("homeassistant","restart", null, null);
}, },
)); ));
}); });

View File

@ -56,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", entityId: null); ConnectionManager().callService("homeassistant", "restart", null, null);
}, },
)); ));
} }
@ -68,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", entityId: null); ConnectionManager().callService("homeassistant","stop", null, null);
}, },
)); ));
} }

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;
String _entityToShow; Entity _entityToShow;
@override @override
void initState() { void initState() {
@ -218,9 +218,8 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
} }
if (_serviceCallSubscription == null) { if (_serviceCallSubscription == null) {
_serviceCallSubscription = _serviceCallSubscription =
eventBus.on<ServiceCallEvent>().listen((event) { eventBus.on<NotifyServiceCallEvent>().listen((event) {
_callService(event.domain, event.service, event.entityId, _notifyServiceCalled(event.domain, event.service, event.entityId);
event.additionalParams);
}); });
} }
@ -318,27 +317,28 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
); );
} }
//TODO remove this shit.... maybe void _notifyServiceCalled(String domain, String service, String entityId) {
void _callService(String domain, String service, String entityId, Map additionalParams) {
_showInfoBottomBar( _showInfoBottomBar(
message: "Calling $domain.$service", message: "Calling $domain.$service",
duration: Duration(seconds: 3) duration: Duration(seconds: 4)
); );
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 = entityId; _entityToShow = HomeAssistant().entities.get(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) {
@ -631,6 +631,7 @@ 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 = [];
@ -725,7 +726,6 @@ 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>[
@ -738,12 +738,13 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
), ),
ConstrainedBox( ConstrainedBox(
constraints: BoxConstraints.tightFor(width: Sizes.entityPageMaxWidth), constraints: BoxConstraints.tightFor(width: Sizes.entityPageMaxWidth),
child: EntityPageLayout(entity: entity, showClose: true,), child: EntityPageLayout(entity: _entityToShow, 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);
} }
} }
@ -799,7 +800,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
_scaffoldKey.currentState.openDrawer(); _scaffoldKey.currentState.openDrawer();
}, },
), ),
bottom: empty ? null : TabBar( bottom: (empty || _entityToShow != null) ? null : TabBar(
controller: _viewsTabController, controller: _viewsTabController,
tabs: buildUIViewTabs(), tabs: buildUIViewTabs(),
isScrollable: true, isScrollable: true,
@ -808,7 +809,8 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
]; ];
}, },
body: mainScrollBody body: mainScrollBody,
controller: _mainScrollController,
); );
} }
@ -874,12 +876,24 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
body: _buildScaffoldBody(true) body: _buildScaffoldBody(true)
); );
} else { } else {
return Scaffold( return WillPopScope(
key: _scaffoldKey, child: Scaffold(
drawer: _buildAppDrawer(), key: _scaffoldKey,
primary: false, drawer: _buildAppDrawer(),
bottomNavigationBar: bottomBar, primary: false,
body: _buildScaffoldBody(false) bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(false)
),
onWillPop: () {
if (_entityToShow != null) {
setState(() {
_entityToShow = null;
});
return Future.value(false);
} else {
return Future.value(true);
}
},
); );
} }
} }

View File

@ -89,17 +89,22 @@ class _PlayMediaPageState extends State<PlayMediaPage> {
} }
Navigator.pop(context); Navigator.pop(context);
ConnectionManager().callService( ConnectionManager().callService(
domain: serviceDomain, serviceDomain,
entityId: entity.entityId, entity.entityId,
service: "play_media", "play_media",
additionalServiceData: { {
"media_content_id": _mediaUrl, "media_content_id": _mediaUrl,
"media_content_type": _contentType "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) {
eventBus.fire(ServiceCallEvent(HomeAssistant().sendFromPlayerId.split(".")[0], "turn_off", HomeAssistant().sendFromPlayerId, null)); ConnectionManager().callService(
HomeAssistant().sendFromPlayerId.split(".")[0],
"turn_off",
HomeAssistant().sendFromPlayerId,
null
);
HomeAssistant().sendFromPlayerId = null; HomeAssistant().sendFromPlayerId = null;
} }
eventBus.fire(ShowEntityPageEvent(entity: entity)); eventBus.fire(ShowEntityPageEvent(entity: entity));

View File

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