Skip to content

Commit

Permalink
chore: checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: ivelin <[email protected]>
  • Loading branch information
ivelin committed Nov 11, 2021
1 parent 39d93e4 commit 7383f6d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/store/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const PNP_SERVICE_CONNECT = 'pnpServiceConnect'
export const PNP_SERVICE_RECONNECT = 'pnpServiceReconnect'
export const PEER_DISCOVER = 'peerDiscover'
export const PEER_CONNECT = 'peerConnect'
export const PEER_DISCONNECT = 'peerDisconnect'
export const PEER_AUTHENTICATE = 'peerAuthenticate'
export const REMOVE_REMOTE_PEER_ID = 'removeRemotePeerId'
export const CHANGE_REMOTE_PEER_ID = 'changeRemotePeerId'
Expand Down
16 changes: 10 additions & 6 deletions src/store/pnp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
PNP_SERVICE_RECONNECT,
PEER_DISCOVER,
PEER_CONNECT,
PEER_DISCONNECT,
PEER_AUTHENTICATE,
REMOVE_REMOTE_PEER_ID,
CHANGE_REMOTE_PEER_ID,
Expand Down Expand Up @@ -560,12 +561,9 @@ const actions = {
await dispatch(PEER_CONNECT, remotePeerId)
},
/**
* Remove remote peer id from local store.
* Maybe the edge device is damaged and its id cannot be recovered.
* In such cases the user will request removal of the existing device
* association and after request local device discovery or direct connection to a new edge device id.
* Disconnect from remote peer id.
*/
async [REMOVE_REMOTE_PEER_ID] ({ state, commit, dispatch }) {
async [PEER_DISCONNECT] ({ state, commit, dispatch }) {
if (state.peerConnectionStatus !== PEER_DISCONNECTED) {
commit(PEER_DISCONNECTING)
const conn = state.peerConnection
Expand All @@ -574,11 +572,17 @@ const actions = {
console.debug('Closing Peer DataConnection.', { conn })
await conn.close()
} catch (err) {
console.debug('Error while closing peer DataConnection.', err)
console.info('Error while closing peer DataConnection.', err)
}
}
commit(PEER_DISCONNECTED)
}
},
/**
* Disconnect and Remove remote peer id from local store.
*/
async [REMOVE_REMOTE_PEER_ID] ({ state, commit, dispatch }) {
await dispatch(PEER_DISCONNECT)
commit(REMOTE_PEER_ID_REMOVED)
},
async [HANDLE_PEER_CONNECTION_ERROR] ({ state, commit, dispatch }, { peerConnection, errMsg }) {
Expand Down
5 changes: 3 additions & 2 deletions src/views/DeviceCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ export default {
forgetDeviceCard: 'myDevices/forget',
updateDisplayName: 'myDevices/updateDisplayName',
updateFromRemote: 'myDevices/updateFromRemote',
setCurrentDevice: 'myDevices/setCurrent'
setCurrentDevice: 'myDevices/setCurrent',
peerConnect: PEER_CONNECT
}),
async fetchEdgeDetails () {
try {
Expand Down Expand Up @@ -332,7 +333,7 @@ export default {
return updated
},
async connectToEdgeDevice () {
await this.$store.dispatch(PEER_CONNECT, this.edgePeerId)
await this.peerConnect(this.edgePeerId)
},
async forgetEdgeDevice () {
// remove from local db and vuex state
Expand Down
20 changes: 6 additions & 14 deletions src/views/DeviceNotificationsConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,14 @@
:sensitive-field="true"
icon-name="key"
/>
<amb-list-item
ref="list-item-apiTarget"
data-cy="list-item-apiTarget"
title="ambianic-notification"
subtitle="Event Name to Trigger"
edit-option="true"
icon-name="target"
/>
<v-list-item>
<v-list-item-content>
<a
href="https://docs.ambianic.ai/users/ifttt/"
target="_new_window"
>
How to configure notifications?
</a>
<a
href="https://docs.ambianic.ai/users/ifttt/"
target="_new_window"
>
How to configure notifications?
</a>
</v-list-item-content>
</v-list-item>
</v-list>
Expand Down
60 changes: 43 additions & 17 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
<v-row
justify="center"
>
<v-card>
<v-card
:loading="isLoading"
:disabled="isLoading"
>
<v-card-title
data-cy="device-card-title"
ref="device-card-title"
Expand Down Expand Up @@ -78,23 +81,28 @@
</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-if="isEdgeConnected">
Connected.
</v-list-item-title>
<v-list-item-title v-else>
Not connected.
</v-list-item-title>
<v-switch
v-model="connectToEdgeSwitch"
:label="`${ isEdgeConnected ? &quot;Connected&quot; : &quot;Disconnected&quot; }`"
/>
</v-list-item-content>
<v-list-item-action>
<v-btn
text
color="info"
to="devicecard"
data-cy="btn-details"
<v-tooltip
bottom
>
<span>Details</span>
<v-icon>info</v-icon>
</v-btn>
<template #activator="{ onDeviceConfigEvents, deviceConfigProps }">
<v-icon
@click="{{ $router.replace('/devicecard') }}"
data-cy="btn-device-config"
ref="btn-device-config"
v-bind="deviceConfigProps"
v-on="onDeviceConfigEvents"
>
tune
</v-icon>
</template>
<span>Device Settings.</span>
</v-tooltip>
</v-list-item-action>
</v-list-item>
<amb-list-item
Expand Down Expand Up @@ -133,6 +141,10 @@ import {
PEER_DISCONNECTING,
PEER_AUTHENTICATING
} from '@/store/mutation-types'
import {
PEER_CONNECT,
PEER_DISCONNECT
} from '@/store/action-types'
export default {
components: {
Expand All @@ -143,20 +155,24 @@ export default {
return {
edgeAddress: undefined,
edgeDeviceError: null,
syncing: false, // is the UI in the process of syncing with remote device data
connectToEdgeSwitch: false,
edgeDisplayName: this.$store.state.myDevices.currentDeviceCard ? this.$store.state.myDevices.currentDeviceCard.displayName : ''
}
},
created () {
},
mounted () {
this.connectToEdgeSwitch = this.isEdgeConnected
},
methods: {
...mapActions({
setCurrentDevice: 'myDevices/setCurrent'
setCurrentDevice: 'myDevices/setCurrent',
peerConnect: PEER_CONNECT,
peerDisconnect: PEER_DISCONNECT
})
},
computed: {
isLoading: function () { return this.isEdgeConnecting || this.isEdgeDisconnecting },
...mapState({
peerConnectionStatus: state => state.pnp.peerConnectionStatus,
isPeerConnectionError: state => state.pnp.peerConnectionStatus === PEER_CONNECTION_ERROR,
Expand Down Expand Up @@ -189,6 +205,16 @@ export default {
console.debug('Current Edge Device Card changed:', { newVal, oldVal })
this.edgeVersion = newVal.version
this.edgeDisplayName = newVal.displayName
},
isEdgeConnected: async function (newVal, oldVal) {
this.connectToEdgeSwitch = newVal
},
connectToEdgeSwitch: async function (newVal, oldVal) {
if (newVal === true) {
await this.peerConnect(this.edgePeerId)
} else {
await this.peerDisconnect()
}
}
}
}
Expand Down

0 comments on commit 7383f6d

Please sign in to comment.