{"id":18665374,"url":"https://github.com/robertklep/homey-mocks","last_synced_at":"2025-04-11T22:31:09.403Z","repository":{"id":142182105,"uuid":"162603929","full_name":"robertklep/homey-mocks","owner":"robertklep","description":"Mock objects for Homey pairing/setting pages","archived":false,"fork":false,"pushed_at":"2022-11-25T05:59:10.000Z","size":14,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T01:53:17.373Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertklep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-20T16:22:03.000Z","updated_at":"2022-11-25T06:16:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b296ff2-5f72-4777-a065-50c6a10d5eb9","html_url":"https://github.com/robertklep/homey-mocks","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fhomey-mocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fhomey-mocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fhomey-mocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertklep%2Fhomey-mocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertklep","download_url":"https://codeload.github.com/robertklep/homey-mocks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248489562,"owners_count":21112601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T08:27:25.183Z","updated_at":"2025-04-11T22:31:09.382Z","avatar_url":"https://github.com/robertklep.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Homey Mocks\n\nMock objects that can be used during the development of custom pairing/settings templates for Homey apps.\n\nInstead of a tedious modify-upload-test cycle, you can create mock event handlers/listeners that can be configured to react like your driver/app. That means that you can develop the pairing/settings templates mostly from the comfort of your desktop or laptop computer.\n\n## How to use\n\nInclude the script at the top of your template:\n\n```html\n\u003c!-- for pairing templates --\u003e\n\u003cscript src='https://cdn.staticaly.com/gh/robertklep/homey-mocks/v0.0.4/homey-pairing-mock.js'\u003e\u003c/script\u003e\n\n\u003c!-- for settings templates --\u003e\n\u003cscript src='/homey.js'\u003e\u003c/script\u003e\n\u003cscript src='https://cdn.staticaly.com/gh/robertklep/homey-mocks/v0.0.4/homey-settings-mock.js'\u003e\u003c/script\u003e\n```\n\n(or download the files and add them to your app, they're not big)\n\nThen, use `Homey.isMock` to run code when the mock object is active:\n\n```javascript\nif (Homey.isMock) {\n}\n```\n\nThat's all.\n\nYou don't necessarily need to remove the includes from production code, because the scripts will not do anything if they're running in a production environment.\n\n## Homey Style Library\n\nIf you want to use the [Homey Style Library](https://apps.developer.homey.app/advanced/custom-views/html-and-css-styling) for your custom views, you can add the CSS and font files explicity:\n```\nHomey.loadStyleLibrary(URL);\n```\n\nWhere `URL` is the URL of your Homey, for example `http://192-168-1-99.homey.homeylocal.com`.\n\n## Pairing API\n\nAll original `Homey` methods are supported.\n\nHowever, some react differently then when run on Homey itself:\n* `Homey.nextView/prevView()`: require that you called `setNextView/setPrevView` first;\n* `Homey.showView(view)`: will try to open the file `${ view }.html` in your browser;\n* `Homey.createDevice()`: will log the device data to console;\n* `Homey.getOptions()`: the `viewId` options is not optional, options should have been set using `Homey.setOptions()` first;\n* `Homey.setNavigationClose()`: does the same as `Homey.done()`;\n* `Homey.done()`: calls `window.alert()`;\n* `Homey.__()`: no-op;\n\n### Mock API methods\n\n* `Homey.isMock`\n\n  Equals `true` when the `Homey` object is mocked.\n\n* `Homey.registerEmitHandler(event, fn)`\n\n  Register a function that will be called when `Homey.emit(event)` is called:\n\n  ```javascript\n  // Register a mock handler for the `start` event.\n  Homey.registerEmitHandler('start', async (event, data) =\u003e {\n    return 'Started!';\n  });\n\n  // The handler above is called when using the following code:\n  const result = await Homey.emit('start', { 'foo': 'bar' });\n  console.log(result); // result is \"Started!\"\n  ```\n\n* `Homey.registerOnHandler(event, fn)`\n\n  Register a function that will be called when `Homey.on(event)` is called:\n\n  ```javascript\n  // Register a mock listener for the `hello` event:\n  Homey.registerOnHandler('hello', (event, cb) =\u003e {\n    cb('Hello to you!', (err, result) =\u003e {\n      console.log(result); // Hi!\n    });\n  });\n\n  // The listener above will be called when using the following code:\n  Homey.on('hello', function(message, callback) {\n    Homey.alert( message ); // Hello to you!\n    callback( null, 'Hi!' ) // send something back, (err, result) style\n  });\n  ```\n\n* `Homey.setZone(zoneId)`\n\n  Set the current zoneId (for use with  `Homey.getZone()`)\n\n* `Homey.setNextView(view)`\n\n  Set the next view (for use with `Homey.nextView()`)\n\n* `Homey.setPrevView(view))`\n\n  Set the previous view (for use with `Homey.prevView()`)\n\n* `Homey.setOptions(viewId, opts)`\n\n  Set view options (for use with `Homey.getOptions()`)\n\n* `Homey.setViewStore(viewId, store)`\n\n  Set view store content (for use with `Homey.getViewStoreValue()`)\n\n## Settings API\n\nAll original `Homey` methods are supported.\n\nHowever, some react differently then when run on Homey itself:\n* `Homey.ready()`: no-op;\n* `Homey.api()`: no actual requests are made, see `Homey.addRoutes()` below;\n* `Homey.__()`: no-op;\n\n### Mock API methods\n\n* `Homey.isMock`\n\n  Equals `true` when the `Homey` object is mocked.\n\n* `Homey.setSettings(settings)`\n\n  Assign application settings (to be retrieved using `Homey.get()`).\n\n* `Homey.addRoutes(routes)`\n\n  Set API routes to match the routes in your `api.js` files. The structure of the `routes` array is basically the same as for `api.js`, where `fn` should implement the (fake) API response.\n\n  For example, this is how you could mock a CRUD store:\n\n  ```javascript\n  let store = {};\n  Homey.addRoutes([\n    {\n      method: 'GET',\n      path:   '/',\n      fn:     function(args, callback) {\n        return callback(null, Object.assign({}, store));\n      }\n    },\n    {\n      method: 'GET',\n      path:   '/:id',\n      fn:     function(args, callback) {\n        const item = store[args.params.id];\n        if (! item) {\n          return callback(Error('NOT_FOUND'));\n        }\n        return callback(null, item);\n      }\n    },\n    {\n      method: 'POST',\n      path:   '/',\n      fn:     function(args, callback) {\n        const id   = ('00000000' + 100000000 * Math.random()).slice(-8);\n        const item = store[id] = args.body;\n        item.id    = id;\n        return callback(null, item);\n      }\n    },\n    {\n      method: 'PUT',\n      path:   '/:id',\n      fn:     function(args, callback) {\n        const item = store[args.params.id];\n        if (! item) {\n          return callback(Error('NOT_FOUND'));\n        }\n        Object.assign(item, args.body);\n        item.id = args.params.id;\n        return callback(null, item);\n      }\n    },\n    {\n      method: 'DELETE',\n      path:   '/:id',\n      fn:     function(args, callback) {\n        const item = store[args.params.id];\n        if (! item) {\n          return callback(Error('NOT_FOUND'));\n        }\n        delete store[args.params.id];\n        return callback();\n      }\n    },\n  ]);\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertklep%2Fhomey-mocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertklep%2Fhomey-mocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertklep%2Fhomey-mocks/lists"}