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) {
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"});
}
});
}

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

@ -1,7 +1,7 @@
part of '../../../main.dart';
class MediaPlayerWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final EntityModel entityModel = EntityModel.of(context);
@ -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}
)
),
);