diff --git a/lib/entity_class/lock_entity.class.dart b/lib/entity_class/lock_entity.class.dart new file mode 100644 index 0000000..0eea6a9 --- /dev/null +++ b/lib/entity_class/lock_entity.class.dart @@ -0,0 +1,12 @@ +part of '../main.dart'; + +class LockEntity extends Entity { + LockEntity(Map rawData) : super(rawData); + + bool get isLocked => state == "locked"; + + @override + Widget _buildStatePart(BuildContext context) { + return LockStateWidget(); + } +} \ No newline at end of file diff --git a/lib/entity_collection.class.dart b/lib/entity_collection.class.dart index 6fb7ef1..f07c95a 100644 --- a/lib/entity_collection.class.dart +++ b/lib/entity_collection.class.dart @@ -44,6 +44,9 @@ class EntityCollection { case 'sensor': { return SensorEntity(rawEntityData); } + case 'lock': { + return LockEntity(rawEntityData); + } case "automation": case "input_boolean": case "switch": { diff --git a/lib/entity_widgets/state/lock_state.dart b/lib/entity_widgets/state/lock_state.dart new file mode 100644 index 0000000..7c7889d --- /dev/null +++ b/lib/entity_widgets/state/lock_state.dart @@ -0,0 +1,32 @@ +part of '../../main.dart'; + +class LockStateWidget extends StatelessWidget { + + void _lock(Entity entity) { + eventBus.fire(new ServiceCallEvent("lock", "lock", entity.entityId, null)); + } + + void _unlock(Entity entity) { + eventBus.fire(new ServiceCallEvent("lock", "unlock", entity.entityId, null)); + } + + @override + Widget build(BuildContext context) { + final entityModel = EntityModel.of(context); + final LockEntity entity = entityModel.entityWrapper.entity; + return SizedBox( + height: 34.0, + child: FlatButton( + onPressed: (() { + entity.isLocked ? _unlock(entity) : _lock(entity); + }), + child: Text( + entity.isLocked ? "UNLOCK" : "LOCK", + textAlign: TextAlign.right, + style: + new TextStyle(fontSize: Sizes.stateFontSize, color: Colors.blue), + ), + ) + ); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 41aaa71..78fee09 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,6 +29,7 @@ part 'entity_class/select_entity.class.dart'; part 'entity_class/other_entity.class.dart'; part 'entity_class/slider_entity.dart'; part 'entity_class/media_player_entity.class.dart'; +part 'entity_class/lock_entity.class.dart'; part 'entity_widgets/common/badge.dart'; part 'entity_widgets/model_widgets.dart'; part 'entity_widgets/default_entity_container.dart'; @@ -57,6 +58,7 @@ part 'entity_widgets/state/climate_state.dart'; part 'entity_widgets/state/cover_state.dart'; part 'entity_widgets/state/date_time_state.dart'; part 'entity_widgets/state/button_state.dart'; +part 'entity_widgets/state/lock_state.dart'; part 'entity_widgets/controls/climate_controls.dart'; part 'entity_widgets/controls/cover_controls.dart'; part 'entity_widgets/controls/light_controls.dart'; diff --git a/lib/mdi.class.dart b/lib/mdi.class.dart index e25507b..4667118 100644 --- a/lib/mdi.class.dart +++ b/lib/mdi.class.dart @@ -22,6 +22,8 @@ class MaterialDesignIcons { "cover.closed": "mdi:window-closed", "cover.closing": "mdi:window-open", "cover.opening": "mdi:window-open", + "lock.locked": "mdi:lock", + "lock.unlocked": "mdi:lock-open", }; static Map _defaultIconsByDeviceClass = {