-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better Organization and Formatting Regarding Sleeping Permissions (#23)
* Update app.json added a page path * Update index.js Updated the index to account for permissions and permission transfers * Update index.r.layout.js Added the additional permission button * Add files via upload Added the permissionsPage and the permissionsPage's layout file * Update index.r.layout.js Changed the coordinates for the stop button * Fix Prettier formatting * Fixed the Prettier Error * Delete app/page/rescuePlanPage.js Deleted accidentally added rescuePlanPage * Update index.js Fixed asycn and storage * Fixed prettier formatting issues * Missed semicolon * Prettier Error Fix * Update app.json Deleted file path to rescuePlanPage * Update index.r.layout.js Fixed stop button positioning * Change that separates the sleep permissions stuff to their own separate files * updated app.json * Separate the sleep functions from the index.js file * Created the sleepFunctions.js file, which separates the sleep functions from the index.js file * changed file name * added google-api-constants.example.js file * added google-api-constants.example.js file * added file * Fixed formatting in sleepFunctions.js * Update index.r.layout.js Fixed duplicate coordinates in index.r.layout.js * Separated some widget created in permissionsPage to be created in permissionsPage.layout * Fixed formatting in index.js * Fixed formatting in index.js * Prettier format fix
- Loading branch information
Showing
5 changed files
with
149 additions
and
104 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Sleep } from '@zos/sensor'; // Import the Sleep module | ||
|
||
const sleep = new Sleep(); | ||
|
||
// Function to handle the sleep button click and permissions | ||
export function onClickSleepButton(jsonstringPermissions) { | ||
console.log('Sleep button pressed. in sleepFunctions.js'); | ||
|
||
// Log the received JSON string of permissions | ||
console.log('Received JSON string of permissions:', jsonstringPermissions); | ||
|
||
try { | ||
// Parse the JSON string to access the permissions as an object | ||
const permissions = JSON.parse(jsonstringPermissions); | ||
|
||
// Log the parsed permissions object | ||
console.log('Parsed permissions:', permissions); | ||
|
||
if (permissions) { | ||
Object.entries(permissions).forEach(([key, value]) => { | ||
if (value === true) { | ||
console.log(`Permission for ${key} is granted.`); | ||
|
||
// Actual data extraction based on the granted permission | ||
switch (key) { | ||
case 'sleepScore': | ||
getSleepInfo('score'); | ||
break; | ||
case 'startEndTime': | ||
getSleepInfo('startTime'); | ||
getSleepInfo('endTime'); | ||
break; | ||
case 'deepSleepTime': | ||
getSleepInfo('deepTime'); | ||
break; | ||
case 'totalSleepTime': | ||
getSleepInfo('totalTime'); | ||
break; | ||
case 'wakeStage': | ||
getStageConstantObj('WAKE_STAGE'); | ||
break; | ||
case 'remStage': | ||
getStageConstantObj('REM_STAGE'); | ||
break; | ||
case 'lightStage': | ||
getStageConstantObj('LIGHT_STAGE'); | ||
break; | ||
case 'deepStage': | ||
getStageConstantObj('DEEP_STAGE'); | ||
break; | ||
default: | ||
console.log(`No action defined for permission: ${key}`); | ||
} | ||
} else { | ||
console.log(`Permission for ${key} is denied.`); | ||
} | ||
}); | ||
} else { | ||
console.log('No permissions found in the parsed object.'); | ||
} | ||
} catch (error) { | ||
console.error('Error parsing permissions JSON:', error); | ||
} | ||
} | ||
|
||
// Extract sleep info (getInfo method) | ||
export function getSleepInfo(infoKey) { | ||
const info = sleep.getInfo(); | ||
|
||
if (info) { | ||
if (info.hasOwnProperty(infoKey)) { | ||
console.log(`${infoKey}: ${info[infoKey]}`); | ||
} else { | ||
console.log(`No data for ${infoKey}`); | ||
} | ||
} else { | ||
console.log('No sleep data available'); | ||
} | ||
} | ||
|
||
// Extract stage constant | ||
export function getStageConstantObj(stageKey) { | ||
const sleepStageConstants = sleep.getStageConstantObj(); | ||
|
||
if (sleepStageConstants && sleepStageConstants.hasOwnProperty(stageKey)) { | ||
console.log(`${stageKey}: ${sleepStageConstants[stageKey]}`); | ||
} else { | ||
console.log(`No data for ${stageKey}`); | ||
} | ||
} |