Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
出现此问题一般是由于高德 API 申请时选错『服务平台』导致,注意请选择『web 端』,而不是 『web 服务』。

## 版本更新日志
### v1.0(2019.03.11)
1. 本次发布时对应的HomeAssistant版本0.89.1
2. 安装:拷贝 www 、panels 、custom_components 文件夹至 Home Assistant 配置文件夹
3. 配置:config.js中填写对应信息
4. 功能:支持HomeAssistant最新的person类型(强烈建议使用这个)。在HomeASsistant中新建group分组,将person或device_tracker添加到组中,在config.js中配置MapTrackerGroupName组名即可
5. 原有的配置细节见github中的原说明信息

### 0.0.3
1. 增加路径图示;
2. 支持新版授权机制。
Expand Down
2 changes: 1 addition & 1 deletion custom_components/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
})
}, extra=vol.ALLOW_EXTRA)

SIGNIFICANT_DOMAINS = ('thermostat', 'climate', 'device_tracker')
SIGNIFICANT_DOMAINS = ('thermostat', 'climate', 'device_tracker','person', 'water_heater')
IGNORE_DOMAINS = ('zone', 'scene',)


Expand Down
14 changes: 13 additions & 1 deletion www/custom_ui/inkwavemap/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ HomeAssistantWebAPIUrl="./../../.."
GaodeMapKey=""


// 永久Token(HomeAssistant 0.77.2版本以上时可用)
// HomeAssistant 0.77.2版本以后,HomeAssistant登录后如果未启用记住密码,墨澜地图将无法自行获取Token(配置了正确的LongTimeToken后可以正常使用)
// 获取方式见:https://bbs.hassbian.com/thread-4695-1-1.html
// (选填)
LongTimeToken=""



// 指定追踪设备ID(多个设备时用半角逗号做分隔“,”,如"xiaomi8_Self,iphoneX_Mother,iphone8")
// 不指定时默认显示全部可追踪的设备
// (选填)
DeviceTrackerIDList=""


//指定追踪多设备的group组名称,如:maptracker
//强烈建议使用group组模式,支持HomeAssistant0.88版本中的PERSON组件
//配置group组模式后,DeviceTrackerIDList无需再填写
// (选填)
MapTrackerGroupName=""
213 changes: 149 additions & 64 deletions www/custom_ui/inkwavemap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,37 @@ var newToken = null;
$(function() {
//alert(txtDrawStart);
storage=window.localStorage;
authToken = storage.getItem("authToken"); //旧版模式
newTokens = JSON.parse(storage.getItem("tokens"));
newToken = newTokens.token_type + " " + newTokens.access_token; //新版模式
try{
authToken = storage.getItem("authToken"); //旧版模式
newTokens = JSON.parse(storage.getItem("tokens")); //新版HA:0.76~0.77.1
}
catch(ex){
null;
}

if (LongTimeToken != "") //config.js配置的长期有效token
{
newToken = LongTimeToken;
}
else
{
if (newTokens == null)
{
newTokens = JSON.parse(storage.getItem("hassTokens")); //新版0.77.2
}
if (newTokens != null)
{
newToken = newTokens.token_type + " " + newTokens.access_token; //新版模式
}
}


if (authToken == null && newToken == null)
{
alert("获取授权token失败");
alert("如果HomeAssistant版本是0.77.2版本以上,登录HomeAssistant后保存密码(或者在config.js中配置LongTimeToken),再刷新此页面");
return;
}

getDataMode = "client"; //不再使用server模式,client模式安全性没问题

Expand Down Expand Up @@ -108,11 +135,7 @@ $(function() {

});

if (getDataMode == "client"){
url = HomeAssistantWebAPIUrl + "/api/config";
}else{
url = phpUrl + "?type=getConfig";
}
url = HomeAssistantWebAPIUrl + "/api/config";
//alert(url);
$.ajax({
type: "GET",
Expand Down Expand Up @@ -147,11 +170,7 @@ $(function() {
//mengqi
//读取所有的zone信息
var arrZone = Array();
if (getDataMode == "client"){
url = HomeAssistantWebAPIUrl + "/api/states";
}else{
url = phpUrl + "?type=getStates";
}
url = HomeAssistantWebAPIUrl + "/api/states";
$.ajax({
type: "GET",
url: url,
Expand Down Expand Up @@ -304,15 +323,20 @@ function LoadStorage(){
}

function getLocationData(deviceId){
var str_deviceid = "device_tracker." + deviceId;
var str_deviceid = "";//"device_tracker." + deviceId;
var str_queryTimeFrom = getStandardDatetime($('#queryTimeFrom').datetimebox('getValue'));
var str_queryTimeTo = getStandardDatetime($('#queryTimeTo').datetimebox('getValue'));

if (getDataMode == "client"){
url = HomeAssistantWebAPIUrl + "/api/history/period/"+ str_queryTimeFrom+ "?end_time="+ str_queryTimeTo+ "&filter_entity_id="+ str_deviceid;
}else{
url = phpUrl + "?type=getHistoryPeriodForDeviceId&timeFrom="+str_queryTimeFrom+"&timeTo="+str_queryTimeTo+"&deviceId="+deviceId;
if (deviceId.indexOf("person.") == -1 && deviceId.indexOf("device_tracker.") == -1)
{
str_deviceid = "device_tracker." + deviceId;
}
else
{
str_deviceid = deviceId;
}

url = HomeAssistantWebAPIUrl + "/api/history/period/"+ str_queryTimeFrom+ "?end_time="+ str_queryTimeTo+ "&filter_entity_id="+ str_deviceid;

var arr = new Array();
//alert(url);
Expand All @@ -332,6 +356,14 @@ function getLocationData(deviceId){
$.each(datajson, function (i, n)
{
if (n.attributes["source_type"] == "gps")
{
arr.push({
'longitude': n.attributes['longitude'],
'latitude': n.attributes['latitude'],
'updatedate': getDatetime(n.last_updated),
'lnglat': [ n.attributes['longitude'],n.attributes['latitude']]
});
}else if (n.attributes["latitude"] != undefined && n.attributes["longitude"] != null)
{
arr.push({
'longitude': n.attributes['longitude'],
Expand Down Expand Up @@ -365,11 +397,16 @@ function trackBtnShow(){

function getDevice(deviceId) {
var getDeviceFun = function() {
if (getDataMode == "client"){
url = HomeAssistantWebAPIUrl + "/api/states/device_tracker." + deviceId;
}else{
url = phpUrl + "?type=getStatesForDeviceId&deviceId="+ deviceId;
var dId = deviceId;
if (deviceId.indexOf("person.") == -1 && deviceId.indexOf("device_tracker.") == -1)
{
dId = "device_tracker."+ deviceId;
}
else
{
dId = deviceId;
}
url = HomeAssistantWebAPIUrl + "/api/states/" + dId;
$.ajax({
type: "GET",
url: url,
Expand Down Expand Up @@ -433,51 +470,99 @@ $(document).on("zoomchange", function() {
});
$(document).on("mapInitFinished", function() {
syncToolbarState(['zoomin', 'zoomout', 'traffic', 'homepoint', 'homerange', 'devicelist']);
if (getDataMode == "client"){

if (MapTrackerGroupName == "")
{
url = HomeAssistantWebAPIUrl + "/api/states/group.all_devices";
}else{
url = phpUrl + "?type=getAllDevices";
$.ajax({
type: "GET",
url: url,
beforeSend: function(request) {
request.setRequestHeader("x-ha-access", authToken);
request.setRequestHeader("Authorization", newToken);
},
cache: false,
async: true,
success: function(data) {
if(null == data) {
return;
}
if(typeof(data) === 'string') {
data = $.parseJSON(data);
}
if(null == data.attributes) {
return;
}
if(null == data.attributes.entity_id) {
return;
}
var idlist = DeviceTrackerIDList.replace("device_tracker.","");
//var PersonIDList = PersonIDList
for(var index in data.attributes.entity_id) {
var deviceFulId = data.attributes.entity_id[index];
var deviceId = deviceFulId.replace("device_tracker.", "");
if (idlist!="" && (idlist+",").indexOf(deviceId) == -1){
continue;
}
insertDeviceList(0, {
//checked: true,
id: deviceId,
name: 'loading...',
state: '---'
});
getDevice(deviceId);
}
}
});
}
$.ajax({
type: "GET",
url: url,
beforeSend: function(request) {
request.setRequestHeader("x-ha-access", authToken);
request.setRequestHeader("Authorization", newToken);
},
cache: false,
async: true,
success: function(data) {
if(null == data) {
return;
}
if(typeof(data) === 'string') {
data = $.parseJSON(data);
}
if(null == data.attributes) {
return;
}
if(null == data.attributes.entity_id) {
return;
}
var idlist = DeviceTrackerIDList.replace("device_tracker.","");
for(var index in data.attributes.entity_id) {
var deviceFulId = data.attributes.entity_id[index];
var deviceId = deviceFulId.replace("device_tracker.", "");
if (idlist!="" && idlist+",".indexOf(deviceId) == -1){
continue;
}
insertDeviceList(0, {
//checked: true,
id: deviceId,
name: 'loading...',
state: '---'
});
getDevice(deviceId);
}
}
});
else{
url = HomeAssistantWebAPIUrl + "/api/states/group."+MapTrackerGroupName;
$.ajax({
type: "GET",
url: url,
beforeSend: function(request) {
request.setRequestHeader("x-ha-access", authToken);
request.setRequestHeader("Authorization", newToken);
},
cache: false,
async: true,
success: function(data) {
if(null == data) {
return;
}
if(typeof(data) === 'string') {
data = $.parseJSON(data);
}
if(null == data.attributes) {
return;
}
if(null == data.attributes.entity_id) {
return;
}
var idlist = DeviceTrackerIDList.replace("device_tracker.","");
//var PersonIDList = PersonIDList
for(var index in data.attributes.entity_id) {
var deviceFulId = data.attributes.entity_id[index];
var deviceId = deviceFulId;
//var deviceId = deviceFulId.replace("device_tracker.", "");
//if (idlist!="" && (idlist+",").indexOf(deviceId) == -1){
// continue;
//}
insertDeviceList(0, {
//checked: true,
id: deviceId,
name: 'loading...',
state: '---'
});
getDevice(deviceId);
}
}
});
}

});


$(document).on("updateDrivingTime", function(event, params) {
var strState = null;
var strState_r = getDeviceListValue(params['deviceId'],'state_r');
Expand Down