Resolves #146 Lock support

This commit is contained in:
Yegor Vialov 2018-11-23 19:18:17 +02:00
parent fc8f2f200f
commit 809a1a1c8c
5 changed files with 51 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -44,6 +44,9 @@ class EntityCollection {
case 'sensor': { case 'sensor': {
return SensorEntity(rawEntityData); return SensorEntity(rawEntityData);
} }
case 'lock': {
return LockEntity(rawEntityData);
}
case "automation": case "automation":
case "input_boolean": case "input_boolean":
case "switch": { case "switch": {

View File

@ -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),
),
)
);
}
}

View File

@ -29,6 +29,7 @@ part 'entity_class/select_entity.class.dart';
part 'entity_class/other_entity.class.dart'; part 'entity_class/other_entity.class.dart';
part 'entity_class/slider_entity.dart'; part 'entity_class/slider_entity.dart';
part 'entity_class/media_player_entity.class.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/common/badge.dart';
part 'entity_widgets/model_widgets.dart'; part 'entity_widgets/model_widgets.dart';
part 'entity_widgets/default_entity_container.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/cover_state.dart';
part 'entity_widgets/state/date_time_state.dart'; part 'entity_widgets/state/date_time_state.dart';
part 'entity_widgets/state/button_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/climate_controls.dart';
part 'entity_widgets/controls/cover_controls.dart'; part 'entity_widgets/controls/cover_controls.dart';
part 'entity_widgets/controls/light_controls.dart'; part 'entity_widgets/controls/light_controls.dart';

View File

@ -22,6 +22,8 @@ class MaterialDesignIcons {
"cover.closed": "mdi:window-closed", "cover.closed": "mdi:window-closed",
"cover.closing": "mdi:window-open", "cover.closing": "mdi:window-open",
"cover.opening": "mdi:window-open", "cover.opening": "mdi:window-open",
"lock.locked": "mdi:lock",
"lock.unlocked": "mdi:lock-open",
}; };
static Map _defaultIconsByDeviceClass = { static Map _defaultIconsByDeviceClass = {