Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thermostatMode issue #546

Open
Wuttiwong opened this issue Mar 8, 2022 · 1 comment
Open

thermostatMode issue #546

Wuttiwong opened this issue Mar 8, 2022 · 1 comment

Comments

@Wuttiwong
Copy link

i try to using ac_unit with trait like this

app.onSync((body) => {
return {
requestId: body.requestId,
payload: {
agentUserId: USER_ID,
devices: [{
id: '123',
type: 'action.devices.types.AC_UNIT',
traits: [
'action.devices.traits.FanSpeed',
'action.devices.traits.OnOff',
'action.devices.traits.TemperatureSetting',
],
name: {
defaultNames: ['Air Condition'],
name: 'Air Condition',
nicknames: ['Air Condition'],
},
deviceInfo: {
manufacturer: 'smart-home-inc',
model: 'hs1234',
hwVersion: '3.2',
swVersion: '11.4',
},
willReportState: true,
attributes: {
availableThermostatModes: [
'off',
'heat',
'on',
],
thermostatTemperatureRange: {
minThresholdCelsius: 15,
maxThresholdCelsius: 30,
},
pausable: true,
availableFanSpeeds: {
speeds: [{
speed_name: 'speed_low',
speed_values: [{
speed_synonym: ['low'],
lang: 'en',
}],
},
{
speed_name: 'speed_medium',
speed_values: [
{
speed_synonym: ['medium'],
lang: 'en',
},
],
},
{
speed_name: 'speed_high',
speed_values: [
{
speed_synonym: ['high'],
lang: 'en',
},
],
},
],
ordered: true,
},
commandOnlyFanSpeed: true,
supportsFanSpeedPercent: true,
queryOnlyTemperatureSetting: true,
thermostatTemperatureUnit: 'C',
},
}],
},
};
});

const queryFirebase = async (deviceId) => {
const snapshot = await firebaseRef.child(deviceId).once('value');
const snapshotVal = snapshot.val();
return {
on: snapshotVal.OnOff.on,
currentFanSpeedSetting: snapshotVal.FanSpeed.currentFanSpeedSetting,
currentFanSpeedPercent: snapshotVal.FanSpeed.currentFanSpeedPercent,
thermostatMode: snapshotVal.TemperatureSetting.thermostatMode,
};
};

when i running it, its return this error message at firebase
TypeError: Cannot read property 'thermostatMode' of undefined

please help me

@armendpe
Copy link

armendpe commented Feb 8, 2024

The error message "Cannot read property 'thermostatMode' of undefined" indicates that the thermostatMode property is being accessed on an undefined object. This suggests that snapshotVal.TemperatureSetting is undefined.

To resolve this , you should first ensure that the TemperatureSetting property exists within your Firebase data structure for the specified deviceId. If it does not exist, you need to handle this case gracefully in your code.

You can modify the queryFirebase function to check if snapshotVal.TemperatureSetting exists before accessing its properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants