Pre release/0.7.1 #488

Merged
estevez-dev merged 10 commits from pre-release/0.7.1 into master 2019-10-29 19:35:11 +02:00
26 changed files with 193 additions and 158 deletions

View File

@ -25,9 +25,12 @@ class _AlarmControlPanelControlsWidgetWidgetState extends State<AlarmControlPane
void _callService(AlarmControlPanelEntity entity, String service) {
eventBus.fire(new ServiceCallEvent(
entity.domain, service, entity.entityId,
{"code": "$code"}));
ConnectionManager().callService(
entity.domain,
service,
entity.entityId,
{"code": "$code"}
);
setState(() {
code = "";
});
@ -58,7 +61,12 @@ class _AlarmControlPanelControlsWidgetWidgetState extends State<AlarmControlPane
FlatButton(
child: new Text("Yes"),
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();
},
),

View File

@ -83,7 +83,12 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
_tempThrottleTimer = Timer(Duration(seconds: 2), () {
setState(() {
_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);
});
});
@ -101,7 +106,12 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
_targetTempThrottleTimer = Timer(Duration(seconds: 2), () {
setState(() {
_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);
});
});
@ -111,7 +121,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() {
_tmpTargetHumidity = value.roundToDouble();
_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);
});
}
@ -120,7 +130,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() {
_tmpHVACMode = value;
_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);
});
}
@ -129,7 +139,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() {
_tmpSwingMode = value;
_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);
});
}
@ -138,7 +148,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() {
_tmpFanMode = value;
_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);
});
}
@ -147,7 +157,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() {
_tmpPresetMode = value;
_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);
});
}
@ -165,7 +175,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
setState(() {
_tmpAuxHeat = value;
_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);
});
}

View File

@ -18,7 +18,7 @@ class _CoverControlWidgetState extends State<CoverControlWidget> {
setState(() {
_tmpPosition = position.roundToDouble();
_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(() {
_tmpTiltPosition = position.roundToDouble();
_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 {
void _open(CoverEntity entity) {
eventBus.fire(new ServiceCallEvent(
entity.domain, "open_cover_tilt", entity.entityId, null));
ConnectionManager().callService(
entity.domain, "open_cover_tilt", entity.entityId, null);
}
void _close(CoverEntity entity) {
eventBus.fire(new ServiceCallEvent(
entity.domain, "close_cover_tilt", entity.entityId, null));
ConnectionManager().callService(
entity.domain, "close_cover_tilt", entity.entityId, null);
}
void _stop(CoverEntity entity) {
eventBus.fire(new ServiceCallEvent(
entity.domain, "stop_cover_tilt", entity.entityId, null));
ConnectionManager().callService(
entity.domain, "stop_cover_tilt", entity.entityId, null);
}
@override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,9 +28,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() {
_tmpBrightness = value.round();
_changedHere = true;
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId,
{"brightness": _tmpBrightness}));
{"brightness": _tmpBrightness});
});
}
@ -38,9 +38,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() {
_tmpWhiteValue = value.round();
_changedHere = true;
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId,
{"white_value": _tmpWhiteValue}));
{"white_value": _tmpWhiteValue});
});
}
@ -49,9 +49,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
setState(() {
_tmpColorTemp = value.round();
_changedHere = true;
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId,
{"color_temp": _tmpColorTemp}));
{"color_temp": _tmpColorTemp});
});
}
@ -60,9 +60,9 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
_tmpColor = color;
_changedHere = true;
Logger.d( "HS Color: [${color.hue}, ${color.saturation}]");
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
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;
_changedHere = true;
if (_tmpEffect != null) {
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId,
{"effect": "$value"}));
{"effect": "$value"});
}
});
}
@ -227,8 +227,6 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
Widget _buildEffectControl(LightEntity entity) {
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);
if (_tmpEffect!= null && !list.contains(_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);
void _lock(Entity entity) {
eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null));
ConnectionManager().callService("lock", "lock", entity.entityId, null);
}
void _unlock(Entity entity) {
eventBus.fire(new ServiceCallEvent("lock", "unlock", entity.entityId, null));
ConnectionManager().callService("lock", "unlock", entity.entityId, null);
}
@override

View File

@ -56,12 +56,12 @@ class _MediaPlayerSeekBarState extends State<MediaPlayerSeekBar> {
color: Colors.orange,
focusColor: Colors.white,
onPressed: () {
eventBus.fire(ServiceCallEvent(
ConnectionManager().callService(
"media_player",
"media_seek",
"${entity.entityId}",
{"seek_position": _savedPosition}
));
);
setState(() {
_savedPosition = 0;
});
@ -103,12 +103,12 @@ class _MediaPlayerSeekBarState extends State<MediaPlayerSeekBar> {
_seekStarted = false;
Timer(Duration(milliseconds: 500), () {
if (!_seekStarted) {
eventBus.fire(ServiceCallEvent(
ConnectionManager().callService(
"media_player",
"media_seek",
"${entity.entityId}",
{"seek_position": val}
));
);
setState(() {
_changedHere = true;
_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.off) {
Logger.d("${entity.entityId} turn_on");
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "turn_on", entity.entityId,
null));
null);
} else {
Logger.d("${entity.entityId} turn_off");
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "turn_off", entity.entityId,
null));
null);
}
}
}
void _callAction(MediaPlayerEntity entity, String action) {
Logger.d("${entity.entityId} $action");
eventBus.fire(new ServiceCallEvent(
ConnectionManager().callService(
entity.domain, "$action", entity.entityId,
null));
null);
}
@override
@ -264,27 +264,27 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
setState(() {
_changedHere = true;
_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) {
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) {
eventBus.fire(ServiceCallEvent("media_player", "volume_up", entityId, null));
ConnectionManager().callService("media_player", "volume_up", entityId, null);
}
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) {
setState(() {
_newSoundMode = value;
_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(() {
_newSource = source;
_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> {
void setNewState(domain, entityId, newValue) {
eventBus.fire(new ServiceCallEvent(domain, "select_option", entityId,
{"option": "$newValue"}));
ConnectionManager().callService(domain, "select_option", entityId,
{"option": "$newValue"});
}
@override

View File

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

View File

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

View File

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

View File

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

View File

@ -141,8 +141,8 @@ EventBus eventBus = new EventBus();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
const String appName = "HA Client";
const appVersionNumber = "0.7.0";
const appVersionAdd = "";
const appVersionNumber = "0.7.1";
const appVersionAdd = "alpha1";
const appVersion = "$appVersionNumber-$appVersionAdd";
void main() async {

View File

@ -195,7 +195,7 @@ class ConnectionManager {
_messageResolver.remove("${data["id"]}");
} else if (data["type"] == "event") {
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"]);
} else if (data["event"] != null) {
Logger.w("Unhandled event type: ${data["event"]["event_type"]}");
@ -348,7 +348,8 @@ class ConnectionManager {
_currentMessageId += 1;
}
Future callService({String domain, String service, String entityId, Map additionalServiceData}) {
Future callService(String domain, String service, String entityId, Map additionalServiceData) {
eventBus.fire(NotifyServiceCallEvent(domain, service, entityId));
Completer completer = Completer();
Map serviceData = {};
if (entityId != null) {

View File

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

View File

@ -42,7 +42,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
}
void decLocationInterval() {
if (_locationInterval > 1) {
if (_locationInterval > 15) {
setState(() {
_locationInterval = _locationInterval - 1;
});
@ -56,7 +56,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
positiveText: "Sure. Make it so",
negativeText: "What?? No!",
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",
negativeText: "What?? No!",
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 _preventAppRefresh = false;
String _savedSharedText;
String _entityToShow;
Entity _entityToShow;
@override
void initState() {
@ -142,6 +142,9 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
_viewsTabController = TabController(vsync: this, length: currentViewCount);
_previousViewCount = currentViewCount;
}
if (_entityToShow != null) {
_entityToShow = HomeAssistant().entities.get(_entityToShow.entityId);
}
}).catchError((e) {
if (e is HAError) {
_setErrorState(e);
@ -218,9 +221,8 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
}
if (_serviceCallSubscription == null) {
_serviceCallSubscription =
eventBus.on<ServiceCallEvent>().listen((event) {
_callService(event.domain, event.service, event.entityId,
event.additionalParams);
eventBus.on<NotifyServiceCallEvent>().listen((event) {
_notifyServiceCalled(event.domain, event.service, event.entityId);
});
}
@ -318,27 +320,28 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
);
}
//TODO remove this shit.... maybe
void _callService(String domain, String service, String entityId, Map additionalParams) {
void _notifyServiceCalled(String domain, String service, String entityId) {
_showInfoBottomBar(
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) {
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(
context,
MaterialPageRoute(
builder: (context) => EntityViewPage(entityId: entityId),
)
);
}
}*/
}
void _showPage(String path, bool goBackFirst) {
@ -368,12 +371,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
menuItems.add(
UserAccountsDrawerHeader(
accountName: Text(HomeAssistant().userName),
accountEmail: Text(ConnectionManager().displayHostname ?? "Not configured"),
onDetailsPressed: () {
Launcher.launchURLInCustomTab(
url: "${ConnectionManager().httpWebHost}/profile?external_auth=1"
);
},
accountEmail: Text(HomeAssistant().locationName ?? ""),
currentAccountPicture: CircleAvatar(
child: Text(
HomeAssistant().userAvatarText,
@ -636,6 +634,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
}
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final ScrollController _mainScrollController = ScrollController();
Widget _buildScaffoldBody(bool empty) {
List<PopupMenuItem<String>> serviceMenuItems = [];
@ -730,7 +729,6 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
}
} else {
if (_entityToShow != null && MediaQuery.of(context).size.width >= Sizes.tabletMinWidth) {
Entity entity = HomeAssistant().entities.get(_entityToShow);
mainScrollBody = Flex(
direction: Axis.horizontal,
children: <Widget>[
@ -743,12 +741,13 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
),
ConstrainedBox(
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 {
_entityToShow = null;
mainScrollBody = HomeAssistant().buildViews(context, _viewsTabController);
}
}
@ -804,7 +803,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
_scaffoldKey.currentState.openDrawer();
},
),
bottom: empty ? null : TabBar(
bottom: (empty || _entityToShow != null) ? null : TabBar(
controller: _viewsTabController,
tabs: buildUIViewTabs(),
isScrollable: true,
@ -813,7 +812,8 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
];
},
body: mainScrollBody
body: mainScrollBody,
controller: _mainScrollController,
);
}
@ -879,12 +879,24 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
body: _buildScaffoldBody(true)
);
} else {
return Scaffold(
return WillPopScope(
child: Scaffold(
key: _scaffoldKey,
drawer: _buildAppDrawer(),
primary: 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);
ConnectionManager().callService(
domain: serviceDomain,
entityId: entity.entityId,
service: "play_media",
additionalServiceData: {
serviceDomain,
entity.entityId,
"play_media",
{
"media_content_id": _mediaUrl,
"media_content_type": _contentType
}
);
HomeAssistant().sendToPlayerId = entity.entityId;
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;
}
eventBus.fire(ShowEntityPageEvent(entity: entity));

View File

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

View File

@ -1,7 +1,7 @@
name: hass_client
description: Home Assistant Android Client
version: 0.7.0+706
version: 0.7.1+711
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"