Skip to content

Commit

Permalink
feat(temperature): Add last value changed info
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril Beslay Home committed Jul 30, 2024
1 parent 41755fd commit 9b0db79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const RoomTemperatureBox = ({ children, ...props }) => (
<Text id="dashboard.boxes.temperatureInRoom.noTemperatureRecorded" />
</p>
)}
<small class="text-muted">{props.roomName}</small>
<small class="text-muted" title={props.lastValueChanged}>
{props.roomName}
</small>
<br />
</div>
</div>
</div>
Expand Down Expand Up @@ -87,6 +90,7 @@ class RoomTemperatureBoxComponent extends Component {
const boxData = get(props, `${DASHBOARD_BOX_DATA_KEY}TemperatureInRoom.${props.x}_${props.y}`);
const boxStatus = get(props, `${DASHBOARD_BOX_STATUS_KEY}TemperatureInRoom.${props.x}_${props.y}`);
const temperature = get(boxData, 'room.temperature.temperature');
const lastValueChanged = get(boxData, 'room.temperature.lastValueChanged');
const unit = get(boxData, 'room.temperature.unit');
const roomName = get(boxData, 'room.name');

Expand Down Expand Up @@ -115,6 +119,7 @@ class RoomTemperatureBoxComponent extends Component {
<RoomTemperatureBox
{...props}
temperature={temperature}
lastValueChanged={lastValueChanged}
unit={unit}
boxStatus={boxStatus}
roomName={roomName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function getTemperatureInRoom(roomId, options) {

const oneHourAgo = new Date(new Date().getTime() - 1 * 60 * 60 * 1000);
const deviceFeatures = await db.DeviceFeature.findAll({
attributes: ['last_value', 'unit'],
attributes: ['last_value', 'unit', 'last_value_changed'],
include: [
{
model: db.Device,
Expand Down Expand Up @@ -54,6 +54,8 @@ async function getTemperatureInRoom(roomId, options) {
}

let total = 0;
let lastValueChanged = new Date();
lastValueChanged.setDate(lastValueChanged.getDate() - 1);

deviceFeatures.forEach((deviceFeature) => {
let temperature;
Expand All @@ -73,6 +75,9 @@ async function getTemperatureInRoom(roomId, options) {
temperature = deviceFeature.last_value;
}
total += temperature;
if (deviceFeature.last_value_changed > lastValueChanged) {
lastValueChanged = deviceFeature.last_value_changed;
}
});

// we calculate the average value
Expand All @@ -82,6 +87,7 @@ async function getTemperatureInRoom(roomId, options) {
return {
temperature: averageTemperature,
unit: optionsWithDefault.unit,
lastValueChanged,
};
}

Expand Down

0 comments on commit 9b0db79

Please sign in to comment.