Resolves #142 Alarm control panel support
This commit is contained in:
		| @@ -9,34 +9,71 @@ class AlarmControlPanelControlsWidget extends StatefulWidget { | |||||||
|  |  | ||||||
| class _AlarmControlPanelControlsWidgetWidgetState extends State<AlarmControlPanelControlsWidget> { | class _AlarmControlPanelControlsWidgetWidgetState extends State<AlarmControlPanelControlsWidget> { | ||||||
|  |  | ||||||
|   void _disarm(AlarmControlPanelEntity entity, String code) { |   String code = ""; | ||||||
|  |  | ||||||
|  |   void _callService(AlarmControlPanelEntity entity, String service) { | ||||||
|     eventBus.fire(new ServiceCallEvent( |     eventBus.fire(new ServiceCallEvent( | ||||||
|           entity.domain, "alarm_disarm", entity.entityId, |           entity.domain, service, entity.entityId, | ||||||
|           {"code": "$code"})); |           {"code": "$code"})); | ||||||
|  |     setState(() { | ||||||
|  |       code = ""; | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final AlarmControlPanelEntity entity = entityModel.entityWrapper.entity; |     final AlarmControlPanelEntity entity = entityModel.entityWrapper.entity; | ||||||
|  |     List<Widget> buttons = []; | ||||||
|  |     if (entity.state == EntityState.alarm_disarmed) { | ||||||
|  |       buttons.addAll(<Widget>[ | ||||||
|  |           RaisedButton( | ||||||
|  |             onPressed: () => _callService(entity, "alarm_arm_home"), | ||||||
|  |             child: Text("ARM HOME"), | ||||||
|  |           ), | ||||||
|  |           RaisedButton( | ||||||
|  |             onPressed: () => _callService(entity, "alarm_arm_away"), | ||||||
|  |             child: Text("ARM AWAY"), | ||||||
|  |           ) | ||||||
|  |         ] | ||||||
|  |       ); | ||||||
|  |     } else { | ||||||
|  |       buttons.add( | ||||||
|  |         RaisedButton( | ||||||
|  |           onPressed: () => _callService(entity, "alarm_disarm"), | ||||||
|  |           child: Text("DISARM"), | ||||||
|  |         ) | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|     return Column( |     return Column( | ||||||
|       crossAxisAlignment: CrossAxisAlignment.center, |       crossAxisAlignment: CrossAxisAlignment.center, | ||||||
|  |  | ||||||
|       children: <Widget>[ |       children: <Widget>[ | ||||||
|         TextField( |         Container( | ||||||
|  |           width: 150.0, | ||||||
|  |           child: TextField( | ||||||
|             //focusNode: _focusNode, |             //focusNode: _focusNode, | ||||||
|             obscureText: true, |               obscureText: true, | ||||||
|             /*controller: new TextEditingController.fromValue( |               controller: new TextEditingController.fromValue( | ||||||
|                 new TextEditingValue( |                   new TextEditingValue( | ||||||
|                     text: _tmpValue, |                       text: code, | ||||||
|                     selection: |                       selection: | ||||||
|                     new TextSelection.collapsed(offset: _tmpValue.length) |                       new TextSelection.collapsed(offset: code.length) | ||||||
|                 ) |                   ) | ||||||
|             ),*/ |               ), | ||||||
|             onChanged: (value) { |               onChanged: (value) { | ||||||
|               Logger.d('Alarm code: $value'); |                 code = value; | ||||||
|             }) |               } | ||||||
|       ], |           ) | ||||||
|  |         ), | ||||||
|  |         Wrap( | ||||||
|  |           alignment: WrapAlignment.center, | ||||||
|  |           spacing: 10.0, | ||||||
|  |           runSpacing: 1.0, | ||||||
|  |           children: buttons | ||||||
|  |         ) | ||||||
|  |       ] | ||||||
|  |  | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user