zha_map WIP: get inital data
This commit is contained in:
parent
2f517a3ad5
commit
293b5e0242
@ -317,10 +317,27 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isServiceExist(String service) {
|
||||||
|
return services != null &&
|
||||||
|
services.isNotEmpty &&
|
||||||
|
services.containsKey(service);
|
||||||
|
}
|
||||||
|
|
||||||
void _createUI() {
|
void _createUI() {
|
||||||
if (!autoUi && (_rawLovelaceData != null)) {
|
if (!autoUi && (_rawLovelaceData != null)) {
|
||||||
Logger.d("Creating Lovelace UI");
|
Logger.d("Creating Lovelace UI");
|
||||||
ui = HomeAssistantUI(_rawLovelaceData);
|
ui = HomeAssistantUI(_rawLovelaceData);
|
||||||
|
if (isServiceExist('zha_map')) {
|
||||||
|
panels.add(
|
||||||
|
Panel(
|
||||||
|
id: 'haclient_zha',
|
||||||
|
componentName: 'haclient_zha',
|
||||||
|
title: 'ZHA',
|
||||||
|
urlPath: '/haclient_zha',
|
||||||
|
icon: 'mdi:zigbee'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger.e("No lovelace config!!!!");
|
Logger.e("No lovelace config!!!!");
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,7 @@ part 'pages/widgets/page_loading_error.dart';
|
|||||||
part 'pages/panel.page.dart';
|
part 'pages/panel.page.dart';
|
||||||
part 'pages/main/main.page.dart';
|
part 'pages/main/main.page.dart';
|
||||||
part 'pages/integration_settings.page.dart';
|
part 'pages/integration_settings.page.dart';
|
||||||
|
part 'pages/zha_page.dart';
|
||||||
part 'home_assistant.class.dart';
|
part 'home_assistant.class.dart';
|
||||||
part 'pages/log.page.dart';
|
part 'pages/log.page.dart';
|
||||||
part 'pages/entity.page.dart';
|
part 'pages/entity.page.dart';
|
||||||
@ -250,6 +251,7 @@ class _HAClientAppState extends State<HAClientApp> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
"/whats-new": (context) => WhatsNewPage(),
|
"/whats-new": (context) => WhatsNewPage(),
|
||||||
|
"/haclient_zha": (context) => ZhaPage(),
|
||||||
"/auth": (context) => new standaloneWebview.WebviewScaffold(
|
"/auth": (context) => new standaloneWebview.WebviewScaffold(
|
||||||
url: "${ConnectionManager().oauthUrl}",
|
url: "${ConnectionManager().oauthUrl}",
|
||||||
appBar: new AppBar(
|
appBar: new AppBar(
|
||||||
|
@ -57,7 +57,7 @@ class _PlayMediaPageState extends State<PlayMediaPage> {
|
|||||||
_loaded = false;
|
_loaded = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_isMediaExtractorExist = HomeAssistant().services.containsKey("media_extractor");
|
_isMediaExtractorExist = HomeAssistant().isServiceExist("media_extractor");
|
||||||
//_useMediaExtractor = _isMediaExtractorExist;
|
//_useMediaExtractor = _isMediaExtractorExist;
|
||||||
_players = HomeAssistant().entities.getByDomains(domains: ["media_player"]);
|
_players = HomeAssistant().entities.getByDomains(domains: ["media_player"]);
|
||||||
setState(() {
|
setState(() {
|
||||||
|
90
lib/pages/zha_page.dart
Normal file
90
lib/pages/zha_page.dart
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
part of '../main.dart';
|
||||||
|
|
||||||
|
class ZhaPage extends StatefulWidget {
|
||||||
|
ZhaPage({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ZhaPageState createState() => new _ZhaPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ZhaPageState extends State<ZhaPage> {
|
||||||
|
|
||||||
|
List data = [];
|
||||||
|
String error = "";
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadData() async {
|
||||||
|
setState(() {
|
||||||
|
data.clear();
|
||||||
|
error = "";
|
||||||
|
});
|
||||||
|
ConnectionManager().sendSocketMessage(
|
||||||
|
type: 'zha_map/devices'
|
||||||
|
).then((response){
|
||||||
|
setState(() {
|
||||||
|
data = response['devices'];
|
||||||
|
});
|
||||||
|
}).catchError((e){
|
||||||
|
setState(() {
|
||||||
|
error = '$e';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
Widget body;
|
||||||
|
if (error.isNotEmpty) {
|
||||||
|
body = PageLoadingError(errorText: error,);
|
||||||
|
} else if (data.isEmpty) {
|
||||||
|
body = PageLoadingIndicator();
|
||||||
|
} else {
|
||||||
|
List<Widget> devicesListWindet = [];
|
||||||
|
data.forEach((device) {
|
||||||
|
devicesListWindet.add(
|
||||||
|
Card(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
CardHeader(
|
||||||
|
name: '${device['ieee']}',
|
||||||
|
subtitle: Text('${device['manufacturer']}'),
|
||||||
|
),
|
||||||
|
Text('${device['device_type']}'),
|
||||||
|
Text('model: ${device['model']}'),
|
||||||
|
Text('offline: ${device['offline']}'),
|
||||||
|
Text('neighbours: ${device['neighbours'].length}'),
|
||||||
|
Text('raw: $device'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
body = ListView(
|
||||||
|
children: devicesListWindet
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new Scaffold(
|
||||||
|
appBar: new AppBar(
|
||||||
|
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
actions: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.refresh),
|
||||||
|
onPressed: () => _loadData(),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
// Here we take the value from the MyHomePage object that was created by
|
||||||
|
// the App.build method, and use it to set our appbar title.
|
||||||
|
title: new Text('ZHA'),
|
||||||
|
),
|
||||||
|
body: body
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ class Panel {
|
|||||||
icon = Panel.iconsByComponent[componentName];
|
icon = Panel.iconsByComponent[componentName];
|
||||||
}
|
}
|
||||||
isHidden = (componentName == 'kiosk' || componentName == 'states' || componentName == 'profile' || componentName == 'developer-tools');
|
isHidden = (componentName == 'kiosk' || componentName == 'states' || componentName == 'profile' || componentName == 'developer-tools');
|
||||||
isWebView = (componentName != 'config' && componentName != 'lovelace');
|
isWebView = (componentName != 'config' && componentName != 'lovelace' && !componentName.startsWith('haclient'));
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleOpen(BuildContext context) {
|
void handleOpen(BuildContext context) {
|
||||||
@ -34,6 +34,8 @@ class Panel {
|
|||||||
builder: (context) => PanelPage(title: "$title", panel: this),
|
builder: (context) => PanelPage(title: "$title", panel: this),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} else if (componentName.startsWith('haclient')) {
|
||||||
|
Navigator.of(context).pushNamed(urlPath);
|
||||||
} else if (componentName == 'lovelace') {
|
} else if (componentName == 'lovelace') {
|
||||||
HomeAssistant().lovelaceDashboardUrl = this.urlPath;
|
HomeAssistant().lovelaceDashboardUrl = this.urlPath;
|
||||||
HomeAssistant().autoUi = false;
|
HomeAssistant().autoUi = false;
|
||||||
|
Reference in New Issue
Block a user