mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
docs and handling failures looking for sonos devices
This commit is contained in:
22
README.md
22
README.md
@@ -3,3 +3,25 @@
|
|||||||
A bridge between sonos and ?
|
A bridge between sonos and ?
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
bonob is ditributed via docker and can be run in a number of ways
|
||||||
|
|
||||||
|
### Full sonos device auto-discovery by using docker --network host
|
||||||
|
```
|
||||||
|
docker run \
|
||||||
|
-e PORT=3000 \
|
||||||
|
-p 3000 \
|
||||||
|
--network host \
|
||||||
|
simojenki/bonob
|
||||||
|
```
|
||||||
|
|
||||||
|
### Full sonos device auto-discovery by using a sonos seed device, without requiring docker host networking
|
||||||
|
```
|
||||||
|
docker run \
|
||||||
|
-e PORT=3000 \
|
||||||
|
-e BONOB_SONOS_SEED_HOST=192.168.1.123 \
|
||||||
|
-p 3000 \
|
||||||
|
simojenki/bonob
|
||||||
|
```
|
||||||
19
src/sonos.ts
19
src/sonos.ts
@@ -23,7 +23,10 @@ const asDevice = (sonosDevice: SonosDevice) => ({
|
|||||||
port: sonosDevice.Port,
|
port: sonosDevice.Port,
|
||||||
});
|
});
|
||||||
|
|
||||||
const setupDiscovery = (manager: SonosManager, sonosSeedHost?: string): Promise<boolean> => {
|
const setupDiscovery = (
|
||||||
|
manager: SonosManager,
|
||||||
|
sonosSeedHost?: string
|
||||||
|
): Promise<boolean> => {
|
||||||
if (sonosSeedHost == undefined || sonosSeedHost == "") {
|
if (sonosSeedHost == undefined || sonosSeedHost == "") {
|
||||||
logger.info("Trying to auto discover sonos devices");
|
logger.info("Trying to auto discover sonos devices");
|
||||||
return manager.InitializeWithDiscovery(10);
|
return manager.InitializeWithDiscovery(10);
|
||||||
@@ -36,13 +39,23 @@ const setupDiscovery = (manager: SonosManager, sonosSeedHost?: string): Promise<
|
|||||||
export function autoDiscoverySonos(sonosSeedHost?: string): Sonos {
|
export function autoDiscoverySonos(sonosSeedHost?: string): Sonos {
|
||||||
const manager = new SonosManager();
|
const manager = new SonosManager();
|
||||||
|
|
||||||
setupDiscovery(manager, sonosSeedHost).then((r) => {
|
setupDiscovery(manager, sonosSeedHost)
|
||||||
|
.then((r) => {
|
||||||
if (r) logger.info({ devices: manager.Devices.map(asDevice) });
|
if (r) logger.info({ devices: manager.Devices.map(asDevice) });
|
||||||
else logger.warn("Failed to auto discover hosts!");
|
else logger.warn("Failed to auto discover hosts!");
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
logger.warn(`Failed to find sonos devices ${e}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
devices: () => manager.Devices.map(asDevice),
|
devices: () => {
|
||||||
|
try {
|
||||||
|
return manager.Devices.map(asDevice)
|
||||||
|
}catch(e) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user