-
-
Notifications
You must be signed in to change notification settings - Fork 318
Binary sensors: display the date of the last state change on the dashboard #2910
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
base: master
Are you sure you want to change the base?
Changes from all commits
3d30f95
403fa8c
2103ecf
375ccd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { Text } from 'preact-i18n'; | ||
|
|
||
| /** | ||
| * Shared editor option of the "devices" and "devices in room" boxes: when enabled, every | ||
| * binary sensor of the box displays, under its state, the date at which this state was | ||
| * reached (door opened/closed, motion detected...). | ||
| */ | ||
| const DisplayLastStateChangeOption = ({ box, x, y, updateDisplayLastStateChange }) => { | ||
| // The edit dashboard displays every box at once, so a hardcoded id would be duplicated as soon | ||
| // as two devices boxes are on the dashboard, and clicking the label of one would toggle the | ||
| // checkbox of the other. The box coordinates make it unique. | ||
| const inputId = `displayLastStateChange-${x}-${y}`; | ||
| return ( | ||
| <div class="form-group"> | ||
| <label class="custom-switch"> | ||
| <input | ||
| type="checkbox" | ||
| id={inputId} | ||
| name="displayLastStateChange" | ||
| class="custom-switch-input" | ||
| checked={box.display_last_state_change === true} | ||
| onClick={updateDisplayLastStateChange} | ||
| /> | ||
| <span class="custom-switch-indicator" /> | ||
| <span class="custom-switch-description"> | ||
| <Text id="dashboard.boxes.devicesInRoom.displayLastStateChangeLabel" /> | ||
| </span> | ||
| </label> | ||
| <p class="mt-2"> | ||
| <small class="text-muted"> | ||
| <Text id="dashboard.boxes.devicesInRoom.displayLastStateChangeDescription" /> | ||
| </small> | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DisplayLastStateChangeOption; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import { createElement } from 'preact'; | ||
| import { Text } from 'preact-i18n'; | ||
| import get from 'get-value'; | ||
|
|
||
| import { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } from '../../../../../../../server/utils/constants'; | ||
| import { DeviceFeatureCategoriesIcon } from '../../../../../utils/consts'; | ||
| import RelativeTime from '../../../../device/RelativeTime'; | ||
|
|
||
| import BatteryLevelFeature from './BatteryLevelFeature'; | ||
| import BinaryDeviceValue from './BinaryDeviceValue'; | ||
|
|
@@ -89,9 +91,22 @@ const DEVICE_FEATURES_WITHOUT_EXPIRATION = [ | |
| ]; | ||
|
|
||
| const SensorDeviceType = ({ children, ...props }) => { | ||
| const { deviceFeature: feature } = props; | ||
| const { deviceFeature: feature, displayLastStateChange, lastStateChange, user } = props; | ||
| const { category, type } = feature; | ||
|
|
||
| // Enabled per box in the box editor. A binary state alone does not tell when the door was | ||
| // opened: the date of the last state change is displayed right under the state. | ||
| // Restricted to read-only features: writable binary features (a switch, a child lock...) also | ||
| // reach this component through DeviceRow, and DevicesBox does not request any date for them. | ||
| // `lastStateChange` is undefined while the request is in flight, and stays undefined for a | ||
| // feature the server left out (unknown, or not keeping any history), so nothing is displayed | ||
| // until an answer is known: null then really means "no change found in the history". | ||
| const showLastStateChange = | ||
| displayLastStateChange === true && | ||
| feature.read_only === true && | ||
| type === DEVICE_FEATURE_TYPES.SENSOR.BINARY && | ||
| lastStateChange !== undefined; | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| let elementType = get(DISPLAY_BY_FEATURE_CATEGORY_AND_TYPE, `${category}.${type}`); | ||
|
|
||
| if (!elementType) { | ||
|
|
@@ -118,7 +133,18 @@ const SensorDeviceType = ({ children, ...props }) => { | |
| <i class={`mr-2 fe fe-${get(DeviceFeatureCategoriesIcon, `${category}.${type}`)}`} /> | ||
| </td> | ||
| <td>{props.rowName}</td> | ||
| <td class="text-right">{createElement(elementType, props)}</td> | ||
| <td class="text-right"> | ||
| {createElement(elementType, props)} | ||
| {showLastStateChange && ( | ||
| <div class="small text-muted"> | ||
| {lastStateChange ? ( | ||
| <RelativeTime datetime={lastStateChange} language={user ? user.language : null} futureDisabled /> | ||
| ) : ( | ||
| <Text id="dashboard.boxes.devicesInRoom.noLastStateChange" /> | ||
| )} | ||
| </div> | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| )} | ||
|
Comment on lines
+136
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pierre already flagged this layout as not clean, and merging Horizon (#2902) makes it worse: Gladys’s existing relative-time patterns do not stack under a badge: User Presence puts the time inside the badge, Last Seen is the value. On a Horizon pill the quiet place for this is a muted caption under the name, with the Opened/Closed badge staying a single line on the right — same structure as scene rows. Please restyle against a real devices box on Horizon (including a long French relative time) before this ships. “Beautiful by default” is a dashboard contract. |
||
| </td> | ||
| </tr> | ||
| ); | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.