Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add avahi Advertiser to UI #1266

Merged
merged 3 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface HomebridgeConfig {
pin: string;
name: string;
port: number;
advertiser?: 'ciao' | 'bonjour-hap';
advertiser?: 'avahi' | 'ciao' | 'bonjour-hap';
bind?: string | string[];
};
mdns?: {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/server/server.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class HomebridgeNetworkInterfacesDto {
export class HomebridgeMdnsSettingDto {
@IsString()
@IsDefined()
@IsIn(['ciao', 'bonjour-hap'])
@IsIn(['avahi', 'ciao', 'bonjour-hap'])
@ApiProperty()
advertiser: 'ciao' | 'bonjour-hap';
advertiser: 'avahi' | 'ciao' | 'bonjour-hap';
}
40 changes: 40 additions & 0 deletions test/e2e/server.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ describe('ServerController (e2e)', () => {
expect(res.json()).toEqual({ advertiser: 'ciao' });
});

it('GET /server/mdns-advertiser (when set to avahi)', async () => {
const config: HomebridgeConfig = await fs.readJson(configService.configPath);
config.bridge.advertiser = 'avahi';
await fs.writeJson(configService.configPath, config);

const res = await app.inject({
method: 'GET',
path: '/server/mdns-advertiser',
headers: {
authorization,
},
});

expect(res.statusCode).toEqual(200);
expect(res.json()).toEqual({ advertiser: 'avahi' });
});

it('PUT /server/mdns-advertiser (bonjour-hap)', async () => {
const initialConfig: HomebridgeConfig = await fs.readJson(configService.configPath);
delete initialConfig.bridge.advertiser;
Expand Down Expand Up @@ -448,6 +465,29 @@ describe('ServerController (e2e)', () => {
expect(config.bridge.advertiser).toEqual('ciao');
});

it('PUT /server/mdns-advertiser (avahi)', async () => {
const initialConfig: HomebridgeConfig = await fs.readJson(configService.configPath);
delete initialConfig.mdns;
await fs.writeJson(configService.configPath, initialConfig);

const res = await app.inject({
method: 'PUT',
path: '/server/mdns-advertiser',
headers: {
authorization,
},
payload: {
advertiser: 'avahi',
},
});

expect(res.statusCode).toEqual(200);

// check the value was saved
const config = await fs.readJson(configService.configPath);
expect(config.bridge.advertiser).toEqual('avahi');
});

it('PUT /server/mdns-advertiser (invalid value)', async () => {
const initialConfig: HomebridgeConfig = await fs.readJson(configService.configPath);
delete initialConfig.mdns;
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/modules/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h5 class="primary-text mt-3" translate="settings.network.title_network"></h5>
<select class="custom-select" [formControl]="legacyMdnsFormControl"
[attr.aria-label]=" 'settings.mdns_advertiser' | translate">
<option value="bonjour-hap">Bonjour HAP</option>
<option value="avahi">Avahi</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could only display this option if the user is running Linux.

Copy link
Member

@oznu oznu Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe having a way for the UI to check if Avahi is available would be useful, as when running Docker the "avahi" service is only started on the Ubuntu variant of the image by default.

Leave that with me though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we interface with homebridge to report which advertiser was picked in "choose default" mode? see homebridge/HAP-NodeJS#922

<option value="ciao">Ciao</option>
</select>
</div>
Expand Down