mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
ability to specify sonos service name and id
This commit is contained in:
14
src/app.ts
14
src/app.ts
@@ -1,12 +1,20 @@
|
||||
import sonos from "./sonos";
|
||||
import sonos, { bonobService } from "./sonos";
|
||||
import server from "./server";
|
||||
import logger from "./logger"
|
||||
|
||||
const PORT = process.env["PORT"] || 4534;
|
||||
|
||||
const app = server(sonos(process.env["BONOB_SONOS_SEED_HOST"]));
|
||||
const bonob = bonobService(
|
||||
process.env["BONOB_SONOS_SERVICE_NAME"] || "bonob",
|
||||
Number(process.env["BONOS_SONOS_SERVICE_ID"] || "246")
|
||||
)
|
||||
const app = server(
|
||||
sonos(process.env["BONOB_SONOS_SEED_HOST"]),
|
||||
bonob
|
||||
);
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.info(`Listening on ${PORT}`);
|
||||
logger.info(`Listening on ${PORT}`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import express, { Express } from "express";
|
||||
import * as Eta from "eta";
|
||||
import { Sonos, servicesFrom, registrationStatus } from "./sonos";
|
||||
import { Sonos, servicesFrom, registrationStatus, Service } from "./sonos";
|
||||
|
||||
function server(sonos: Sonos): Express {
|
||||
function server(sonos: Sonos, bonob: Service): Express {
|
||||
const app = express();
|
||||
|
||||
app.use(express.static("./web/public"));
|
||||
@@ -12,14 +12,15 @@ function server(sonos: Sonos): Express {
|
||||
app.set("views", "./web/views");
|
||||
|
||||
app.get("/", (_, res) => {
|
||||
sonos.devices().then(devices => {
|
||||
const services = servicesFrom(devices)
|
||||
sonos.devices().then((devices) => {
|
||||
const services = servicesFrom(devices);
|
||||
res.render("index", {
|
||||
devices,
|
||||
services,
|
||||
registration: registrationStatus(services)
|
||||
})
|
||||
})
|
||||
bonob,
|
||||
registration: registrationStatus(services, bonob),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
|
||||
12
src/sonos.ts
12
src/sonos.ts
@@ -18,10 +18,10 @@ export type Service = {
|
||||
|
||||
export type BonobRegistrationStatus = 'registered' | 'not-registered'
|
||||
|
||||
export const BONOB_SERVICE: Service = {
|
||||
name: "bonob",
|
||||
id: 245
|
||||
}
|
||||
export const bonobService = (name: string, id: number): Service => ({
|
||||
name,
|
||||
id
|
||||
})
|
||||
|
||||
export interface Sonos {
|
||||
devices: () => Promise<Device[]>;
|
||||
@@ -41,8 +41,8 @@ export const servicesFrom = (devices: Device[]) =>
|
||||
"name"
|
||||
);
|
||||
|
||||
export const registrationStatus = (services: Service[]): BonobRegistrationStatus => {
|
||||
if(services.find(s => s.id == BONOB_SERVICE.id) != undefined) {
|
||||
export const registrationStatus = (services: Service[], bonob: Service): BonobRegistrationStatus => {
|
||||
if(services.find(s => s.id == bonob.id) != undefined) {
|
||||
return "registered"
|
||||
} else {
|
||||
return "not-registered"
|
||||
|
||||
Reference in New Issue
Block a user