gpt4 book ai didi

java - NestDK 无法初始化和更新 SmokeCOAlarm 对象

转载 作者:行者123 更新时间:2023-11-30 01:36:49 25 4
gpt4 key购买 nike

我尝试在 Thermostat 对象中使用与 SmokeCOAlarm 对象相同的初始化和更新方法,但没有用。

有谁知道如何初始化和更新SmokeCOAlarm 对象?或者 Nest 尚未打开以访问 SmokeCOAlarm 对象?!

以下是我的代码:

public class COSmokeAlarm extends Activity implements
NestAPI.AuthenticationListener, Listener.SmokeCOAlarmListener, Listener.ThermostatListener {

private Listener mUpdateListener;
private NestAPI mNestApi;
private SmokeCOAlarm mSmokeCOAlarm;
private Thermostat mThermostat;
private AccessToken mToken;

TextView txvBattery;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_co_smoke_alarm);

txvBattery = (TextView)findViewById(R.id.txvBattery);

mNestApi = NestAPI.getInstance();//Initial NestAPI, connect Firebase
mToken = Settings.loadAuthToken(this);//Loade AccessToken
authenticate(mToken);
}

private void updateBatteryTextView() {
if (mSmokeCOAlarm != null) {
txvBattery.setText(mSmokeCOAlarm.getBatteryHealth());
}
}

private void authenticate(AccessToken token) {
Log.v("COSmokeAlarm", "Authenticating...");
NestAPI.getInstance().authenticate(token, this);
}

@Override
public void onAuthenticationSuccess() {
Log.v("COSmokeAlarm", "Authentication succeeded.");
fetchData();
}

@Override
public void onAuthenticationFailure(int errorCode) {
Log.v("COSmokeAlarm", "Authentication failed with error: " + errorCode);
}

private void fetchData() {
Log.v("COSmokeAlarm", "Fetching data...");

mUpdateListener = new Listener.Builder()
.setSmokeCOAlarmListener(this)
.setThermostatListener(this)
.build();
mNestApi.addUpdateListener(mUpdateListener);
Toast.makeText(COSmokeAlarm.this, "Success fetching data.", Toast.LENGTH_SHORT).show();
}

@Override
public void onSmokeCOAlarmUpdated(@NonNull SmokeCOAlarm smokeCOAlarm) {
Log.v("COSmokeAlarm", String.format("COSmoke Alarm (%s) updated.", smokeCOAlarm.getDeviceID()));
this.mSmokeCOAlarm = smokeCOAlarm;
updateBatteryTextView();
}

@Override
public void onThermostatUpdated(@NonNull Thermostat thermostat) {
Log.v("COSmokeAlarm", String.format("Thermostat (%s) updated.", thermostat.getDeviceID()));
mThermostat = thermostat;
}
}

最佳答案

转到 Nest 帐户并添加权限“Smoke+CO alarm read v4” enter image description here

然后我们可以访问SmokeCOAlarm 信息。 enter image description here

关于java - NestDK 无法初始化和更新 SmokeCOAlarm 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35006999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com