-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get persistent_notifications for lovelace from websocket. (#1649)
* Get persistent_notifications for lovelace from websocket. * Only fetch notifications on event. * Use collection for notifications.
- Loading branch information
Showing
9 changed files
with
101 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createCollection } from 'home-assistant-js-websocket'; | ||
|
||
const fetchNotifications = conn => conn.sendMessagePromise({ | ||
type: 'persistent_notification/get' | ||
}); | ||
|
||
const subscribeUpdates = (conn, store) => | ||
conn.subscribeEvents( | ||
() => fetchNotifications(conn).then(ntf => store.setState(ntf, true)), | ||
'persistent_notifications_updated' | ||
); | ||
|
||
export const subscribeNotifications = (conn, onChange) => | ||
createCollection( | ||
'_ntf', | ||
fetchNotifications, | ||
subscribeUpdates, | ||
conn, | ||
onChange | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import computeDomain from '../../../common/entity/compute_domain.js'; | ||
|
||
const NOTIFICATION_DOMAINS = [ | ||
'configurator', | ||
'persistent_notification' | ||
]; | ||
|
||
export default function computeNotifications(states) { | ||
return Object.keys(states) | ||
.filter(entityId => NOTIFICATION_DOMAINS.includes(computeDomain(entityId))) | ||
.filter(entityId => computeDomain(entityId) === 'configurator') | ||
.map(entityId => states[entityId]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters