mirror of
https://github.com/lasthead0/yandex2mqtt.git
synced 2025-08-08 09:01:00 +03:00
ESLint refactoring
This commit is contained in:
280
config.orig.js
280
config.orig.js
@@ -1,157 +1,157 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
mqtt: {
|
mqtt: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 1883,
|
port: 1883,
|
||||||
user: 'user',
|
user: 'user',
|
||||||
password: 'password',
|
password: 'password',
|
||||||
},
|
|
||||||
|
|
||||||
https: {
|
|
||||||
privateKey: '/etc/letsencrypt/live/your.domain.ru/privkey.pem',
|
|
||||||
certificate: '/etc/letsencrypt/live/your.domain.ru/fullchain.pem',
|
|
||||||
port: 4433,
|
|
||||||
},
|
|
||||||
|
|
||||||
clients: [
|
|
||||||
{
|
|
||||||
id: '1',
|
|
||||||
name: 'Yandex',
|
|
||||||
clientId: 'client',
|
|
||||||
clientSecret: 'secret',
|
|
||||||
isTrusted: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
users: [
|
|
||||||
{
|
|
||||||
id: '1',
|
|
||||||
username: 'admin',
|
|
||||||
password: 'admin',
|
|
||||||
name: 'Administrator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '2',
|
|
||||||
username: 'user1',
|
|
||||||
password: 'user1',
|
|
||||||
name: 'User',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
devices: [
|
|
||||||
{
|
|
||||||
id: 'haw-002-switch',
|
|
||||||
name: 'Свет в коридоре',
|
|
||||||
room: 'Коридор',
|
|
||||||
type: 'devices.types.light',
|
|
||||||
mqtt: [
|
|
||||||
{
|
|
||||||
instance: 'on',
|
|
||||||
set: '/yandex/controls/light_HaW_002/state/on',
|
|
||||||
state: '/yandex/controls/light_HaW_002/state',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
capabilities: [
|
|
||||||
{
|
|
||||||
type: 'devices.capabilities.on_off',
|
|
||||||
retrievable: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
https: {
|
||||||
id: 'lvr-003-switch',
|
privateKey: '/etc/letsencrypt/live/your.domain.ru/privkey.pem',
|
||||||
name: 'Основной свет',
|
certificate: '/etc/letsencrypt/live/your.domain.ru/fullchain.pem',
|
||||||
room: 'Гостиная',
|
port: 4433,
|
||||||
type: 'devices.types.light',
|
|
||||||
mqtt: [
|
|
||||||
{
|
|
||||||
instance: 'on',
|
|
||||||
set: '/yandex/controls/light_LvR_003/state/on',
|
|
||||||
state: '/yandex/controls/light_LvR_003/state',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
valueMapping: [
|
|
||||||
{
|
|
||||||
type: 'on_off',
|
|
||||||
mapping: [[false, true], [0, 1]], // [yandex, mqtt]
|
|
||||||
},
|
|
||||||
],
|
|
||||||
capabilities: [
|
|
||||||
{
|
|
||||||
type: 'devices.capabilities.on_off',
|
|
||||||
retrievable: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
clients: [
|
||||||
id: 'lvr-001-weather',
|
|
||||||
name: 'В гостиной',
|
|
||||||
room: 'Гостиная',
|
|
||||||
type: 'devices.types.sensor',
|
|
||||||
mqtt: [
|
|
||||||
{
|
{
|
||||||
instance: 'temperature',
|
id: '1',
|
||||||
state: '/yandex/sensors/LvR_001_Weather/temperature',
|
name: 'Yandex',
|
||||||
|
clientId: 'client',
|
||||||
|
clientSecret: 'secret',
|
||||||
|
isTrusted: false,
|
||||||
},
|
},
|
||||||
{
|
],
|
||||||
instance: 'humidity',
|
|
||||||
state: '/yandex/sensors/LvR_001_Weather/humidity',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
properties: [
|
|
||||||
{
|
|
||||||
type: 'devices.properties.float',
|
|
||||||
retrievable: true,
|
|
||||||
parameters: {
|
|
||||||
instance: 'temperature',
|
|
||||||
unit: 'unit.temperature.celsius',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'devices.properties.float',
|
|
||||||
retrievable: true,
|
|
||||||
parameters: {
|
|
||||||
instance: 'humidity',
|
|
||||||
unit: 'unit.percent',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
users: [
|
||||||
id: 'plug-001-flower',
|
|
||||||
name: 'Розетка для цветка',
|
|
||||||
room: 'Гостиная',
|
|
||||||
type: 'devices.types.socket',
|
|
||||||
mqtt: [
|
|
||||||
{
|
{
|
||||||
instance: 'on',
|
id: '1',
|
||||||
set: '/yandex/controls/socket_LvR_002/state/on',
|
username: 'admin',
|
||||||
state: '/yandex/controls/socket_LvR_002/state/on',
|
password: 'admin',
|
||||||
|
name: 'Administrator',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
instance: 'power',
|
id: '2',
|
||||||
state: '/yandex/controls/socket_LvR_002/power',
|
username: 'user1',
|
||||||
|
password: 'user1',
|
||||||
|
name: 'User',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
capabilities: [
|
|
||||||
|
devices: [
|
||||||
{
|
{
|
||||||
type: 'devices.capabilities.on_off',
|
id: 'haw-002-switch',
|
||||||
retrievable: true,
|
name: 'Свет в коридоре',
|
||||||
|
room: 'Коридор',
|
||||||
|
type: 'devices.types.light',
|
||||||
|
mqtt: [
|
||||||
|
{
|
||||||
|
instance: 'on',
|
||||||
|
set: '/yandex/controls/light_HaW_002/state/on',
|
||||||
|
state: '/yandex/controls/light_HaW_002/state',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
capabilities: [
|
||||||
|
{
|
||||||
|
type: 'devices.capabilities.on_off',
|
||||||
|
retrievable: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
|
||||||
properties: [
|
|
||||||
{
|
{
|
||||||
type: 'devices.properties.float',
|
id: 'lvr-003-switch',
|
||||||
retrievable: true,
|
name: 'Основной свет',
|
||||||
parameters: {
|
room: 'Гостиная',
|
||||||
instance: 'power',
|
type: 'devices.types.light',
|
||||||
unit: 'unit.watt',
|
mqtt: [
|
||||||
},
|
{
|
||||||
|
instance: 'on',
|
||||||
|
set: '/yandex/controls/light_LvR_003/state/on',
|
||||||
|
state: '/yandex/controls/light_LvR_003/state',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
valueMapping: [
|
||||||
|
{
|
||||||
|
type: 'on_off',
|
||||||
|
mapping: [[false, true], [0, 1]], // [yandex, mqtt]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
capabilities: [
|
||||||
|
{
|
||||||
|
type: 'devices.capabilities.on_off',
|
||||||
|
retrievable: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
|
||||||
},
|
{
|
||||||
/* --- end */
|
id: 'lvr-001-weather',
|
||||||
],
|
name: 'В гостиной',
|
||||||
|
room: 'Гостиная',
|
||||||
|
type: 'devices.types.sensor',
|
||||||
|
mqtt: [
|
||||||
|
{
|
||||||
|
instance: 'temperature',
|
||||||
|
state: '/yandex/sensors/LvR_001_Weather/temperature',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
instance: 'humidity',
|
||||||
|
state: '/yandex/sensors/LvR_001_Weather/humidity',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
type: 'devices.properties.float',
|
||||||
|
retrievable: true,
|
||||||
|
parameters: {
|
||||||
|
instance: 'temperature',
|
||||||
|
unit: 'unit.temperature.celsius',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'devices.properties.float',
|
||||||
|
retrievable: true,
|
||||||
|
parameters: {
|
||||||
|
instance: 'humidity',
|
||||||
|
unit: 'unit.percent',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 'plug-001-flower',
|
||||||
|
name: 'Розетка для цветка',
|
||||||
|
room: 'Гостиная',
|
||||||
|
type: 'devices.types.socket',
|
||||||
|
mqtt: [
|
||||||
|
{
|
||||||
|
instance: 'on',
|
||||||
|
set: '/yandex/controls/socket_LvR_002/state/on',
|
||||||
|
state: '/yandex/controls/socket_LvR_002/state/on',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
instance: 'power',
|
||||||
|
state: '/yandex/controls/socket_LvR_002/power',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
capabilities: [
|
||||||
|
{
|
||||||
|
type: 'devices.capabilities.on_off',
|
||||||
|
retrievable: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
type: 'devices.properties.float',
|
||||||
|
retrievable: true,
|
||||||
|
parameters: {
|
||||||
|
instance: 'power',
|
||||||
|
unit: 'unit.watt',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
/* --- end */
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
@@ -47,7 +47,7 @@ server.deserializeClient((id, done) => {
|
|||||||
|
|
||||||
server.grant(oauth2orize.grant.code((client, redirectUri, user, ares, done) => {
|
server.grant(oauth2orize.grant.code((client, redirectUri, user, ares, done) => {
|
||||||
const code = utils.getUid(16);
|
const code = utils.getUid(16);
|
||||||
db.authorizationCodes.save(code, client.id, redirectUri, user.id, user.username, (error) => {
|
db.authorizationCodes.save(code, client.id, redirectUri, user.id, user.username, error => {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
return done(null, code);
|
return done(null, code);
|
||||||
});
|
});
|
||||||
@@ -61,7 +61,7 @@ server.grant(oauth2orize.grant.code((client, redirectUri, user, ares, done) => {
|
|||||||
|
|
||||||
server.grant(oauth2orize.grant.token((client, user, ares, done) => {
|
server.grant(oauth2orize.grant.token((client, user, ares, done) => {
|
||||||
const token = utils.getUid(256);
|
const token = utils.getUid(256);
|
||||||
db.accessTokens.save(token, user.id, client.clientId, (error) => {
|
db.accessTokens.save(token, user.id, client.clientId, error => {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
return done(null, token);
|
return done(null, token);
|
||||||
});
|
});
|
||||||
@@ -81,7 +81,7 @@ server.exchange(oauth2orize.exchange.code((client, code, redirectUri, done) => {
|
|||||||
if (redirectUri !== authCode.redirectUri) return done(null, false);
|
if (redirectUri !== authCode.redirectUri) return done(null, false);
|
||||||
|
|
||||||
const token = utils.getUid(256);
|
const token = utils.getUid(256);
|
||||||
db.accessTokens.save(token, authCode.userId, authCode.clientId, (error) => {
|
db.accessTokens.save(token, authCode.userId, authCode.clientId, error => {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
// Add custom params, e.g. the username
|
// Add custom params, e.g. the username
|
||||||
let params = { username: authCode.userName };
|
let params = { username: authCode.userName };
|
||||||
@@ -109,7 +109,7 @@ server.exchange(oauth2orize.exchange.password((client, username, password, scope
|
|||||||
if (password !== user.password) return done(null, false);
|
if (password !== user.password) return done(null, false);
|
||||||
// Everything validated, return the token
|
// Everything validated, return the token
|
||||||
const token = utils.getUid(256);
|
const token = utils.getUid(256);
|
||||||
db.accessTokens.save(token, user.id, client.clientId, (error) => {
|
db.accessTokens.save(token, user.id, client.clientId, error => {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
// Call `done(err, accessToken, [refreshToken], [params])`, see oauth2orize.exchange.code
|
// Call `done(err, accessToken, [refreshToken], [params])`, see oauth2orize.exchange.code
|
||||||
return done(null, token);
|
return done(null, token);
|
||||||
@@ -132,7 +132,7 @@ server.exchange(oauth2orize.exchange.clientCredentials((client, scope, done) =>
|
|||||||
// Everything validated, return the token
|
// Everything validated, return the token
|
||||||
const token = utils.getUid(256);
|
const token = utils.getUid(256);
|
||||||
// Pass in a null for user id since there is no user with this grant type
|
// Pass in a null for user id since there is no user with this grant type
|
||||||
db.accessTokens.save(token, null, client.clientId, (error) => {
|
db.accessTokens.save(token, null, client.clientId, error => {
|
||||||
if (error) return done(error);
|
if (error) return done(error);
|
||||||
// Call `done(err, accessToken, [refreshToken], [params])`, see oauth2orize.exchange.code
|
// Call `done(err, accessToken, [refreshToken], [params])`, see oauth2orize.exchange.code
|
||||||
return done(null, token);
|
return done(null, token);
|
||||||
|
Reference in New Issue
Block a user