Skip to content

Commit 9455aaa

Browse files
committed
protection entity tied to header display
1 parent bfe0ebd commit 9455aaa

8 files changed

Lines changed: 31 additions & 28 deletions

File tree

src/common/map-entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const mapEntitiesByTranslationKey = (
1717
dns_queries_blocked_ratio: 'dns_queries_blocked_ratio',
1818
average_processing_speed: 'average_processing_speed',
1919
safe_searches_enforced: 'safe_searches_enforced',
20+
protection: 'protection',
2021

2122
// not vetted yet
2223
// action_refresh_data: 'action_refresh_data',

src/delegates/utils/get-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const getAdGuardSetup = (
3636
return {
3737
device_id: hole.device_id,
3838
// required for the setup state to work
39-
status: hole.status,
39+
protection: hole.protection,
4040
controls: [],
4141
sensors: [],
4242
switches: [],

src/html/components/pi-icon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const icon = (
2424
// If user has custom badge config, apply it to all AdGuard instances
2525
if (config.badge) {
2626
return {
27-
entity: h.status?.entity_id ?? h.device_id,
27+
entity: h.protection?.entity_id ?? h.device_id,
2828
...config.badge,
2929
};
3030
}
@@ -44,7 +44,7 @@ export const icon = (
4444

4545
// For AdGuard instances, use the base config
4646
return {
47-
entity: h.status?.entity_id ?? h.device_id,
47+
entity: h.protection?.entity_id ?? h.device_id,
4848
...baseConfig,
4949
};
5050
});

src/html/pi-crust.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const createCardHeader = (
2626

2727
const primary = setup.holes[0]!;
2828
const activeCount = setup.holes
29-
.map((h) => h.status)
29+
.map((h) => h.protection)
3030
.filter(
3131
(status) => status !== undefined && stateActive(status, status?.state),
3232
).length;
@@ -59,7 +59,7 @@ export const createCardHeader = (
5959
></ha-icon>
6060
${mixedStatus
6161
? html`${localize(hass, 'card.ui.partial')}`
62-
: stateDisplay(hass, primary.status!)}
62+
: stateDisplay(hass, primary.protection!)}
6363
</div>
6464
</div>
6565
`;

src/types/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface AdGuardDevice {
2929
latest_data_refresh?: EntityInformation;
3030

3131
/** Status of AdGuard */
32-
status?: EntityInformation;
32+
protection?: EntityInformation;
3333

3434
/** Sensors for the AdGuard */
3535
sensors: EntityInformation[];

test/delegates/utils/get-setup.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ describe('get-setup.ts', () => {
217217
entity_id: 'binary_sensor.pi_hole_status_2',
218218
state: 'on',
219219
attributes: { friendly_name: 'AdGuard Status 2' },
220-
translation_key: undefined,
220+
translation_key: 'protection',
221221
};
222222

223223
const device2 = {
224224
device_id: 'adguard_device_2',
225-
status: device2Status,
225+
protection: device2Status,
226226
switches: [device2Switch1, device2Switch2],
227227
sensors: [
228228
{
@@ -281,7 +281,9 @@ describe('get-setup.ts', () => {
281281

282282
// Check second device only has device_id and status, with empty arrays for other properties
283283
expect(result?.holes[1]?.device_id).to.equal('adguard_device_2');
284-
expect(result?.holes[1]?.status).to.deep.equal(device2Status);
284+
console.log(result?.holes[1]?.protection);
285+
console.log(device2Status);
286+
expect(result?.holes[1]?.protection).to.deep.equal(device2Status);
285287
expect(result?.holes[1]?.switches).to.be.an('array').with.lengthOf(0);
286288
expect(result?.holes[1]?.sensors).to.be.an('array').with.lengthOf(0);
287289
expect(result?.holes[1]?.controls).to.be.an('array').with.lengthOf(0);

test/html/components/pi-icon.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('icon.ts', () => {
9090

9191
describe('action handler integration', () => {
9292
it('should call action handlers with correct configurations', async () => {
93-
mockSetup.holes[0]!.status = {
93+
mockSetup.holes[0]!.protection = {
9494
entity_id: 'sensor.pi_hole_status',
9595
state: 'enabled',
9696
attributes: {},
@@ -116,7 +116,7 @@ describe('icon.ts', () => {
116116
});
117117

118118
it('should create default action configurations when no custom badge config', async () => {
119-
mockSetup.holes[0]!.status = {
119+
mockSetup.holes[0]!.protection = {
120120
entity_id: 'sensor.pi_hole_status',
121121
state: 'enabled',
122122
attributes: {},
@@ -143,7 +143,7 @@ describe('icon.ts', () => {
143143
action: 'toggle',
144144
},
145145
};
146-
mockSetup.holes[0]!.status = {
146+
mockSetup.holes[0]!.protection = {
147147
entity_id: 'sensor.pi_hole_status',
148148
state: 'enabled',
149149
attributes: {},
@@ -171,7 +171,7 @@ describe('icon.ts', () => {
171171

172172
it('should handle multiple AdGuard instances with different configurations', async () => {
173173
// First AdGuard with status
174-
mockSetup.holes[0]!.status = {
174+
mockSetup.holes[0]!.protection = {
175175
entity_id: 'sensor.adguard_1_status',
176176
state: 'enabled',
177177
attributes: {},

test/html/pi-crust.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('pi-crust.ts', () => {
5858
// Mock device
5959
mockDevice = {
6060
device_id: 'adguard_device',
61-
status: {
61+
protection: {
6262
entity_id: 'binary_sensor.pi_hole_status',
6363
state: 'on',
6464
attributes: { friendly_name: 'Pi-hole Status' },
@@ -161,7 +161,7 @@ describe('pi-crust.ts', () => {
161161

162162
it('should display green status when Pi-hole is active', async () => {
163163
// Ensure status is 'on'
164-
mockSetup.holes[0]!.status!.state = 'on';
164+
mockSetup.holes[0]!.protection!.state = 'on';
165165

166166
// Render the card header
167167
const result = createCardHeader(
@@ -186,7 +186,7 @@ describe('pi-crust.ts', () => {
186186

187187
it('should display red status when Pi-hole is inactive', async () => {
188188
// Set status to 'off'
189-
mockSetup.holes[0]!.status!.state = 'off';
189+
mockSetup.holes[0]!.protection!.state = 'off';
190190

191191
// Render the card header
192192
const result = createCardHeader(
@@ -214,11 +214,11 @@ describe('pi-crust.ts', () => {
214214
createCardHeader(mockElement, mockSetup, mockHass, mockConfig);
215215

216216
// Verify stateDisplay was called with the correct parameters
217-
expect(stateDisplayStub.calledWith(mockHass, mockSetup.holes[0]!.status)).to
218-
.be.true;
217+
expect(
218+
stateDisplayStub.calledWith(mockHass, mockSetup.holes[0]!.protection),
219+
).to.be.true;
219220
});
220221

221-
222222
// New tests for multiple Pi-hole setup
223223

224224
it('should not display hole count when only one Pi-hole is configured', async () => {
@@ -241,8 +241,8 @@ describe('pi-crust.ts', () => {
241241
const secondDevice = {
242242
...mockDevice,
243243
device_id: 'adguard_device_2',
244-
status: {
245-
...mockDevice.status,
244+
protection: {
245+
...mockDevice.protection,
246246
entity_id: 'binary_sensor.pi_hole_2_status',
247247
state: 'on',
248248
},
@@ -269,8 +269,8 @@ describe('pi-crust.ts', () => {
269269
const secondDevice = {
270270
...mockDevice,
271271
device_id: 'adguard_device_2',
272-
status: {
273-
...mockDevice.status,
272+
protection: {
273+
...mockDevice.protection,
274274
entity_id: 'binary_sensor.pi_hole_2_status',
275275
state: 'off',
276276
},
@@ -301,8 +301,8 @@ describe('pi-crust.ts', () => {
301301
const secondDevice = {
302302
...mockDevice,
303303
device_id: 'adguard_device_2',
304-
status: {
305-
...mockDevice.status,
304+
protection: {
305+
...mockDevice.protection,
306306
entity_id: 'binary_sensor.pi_hole_2_status',
307307
state: 'off',
308308
},
@@ -311,8 +311,8 @@ describe('pi-crust.ts', () => {
311311
const thirdDevice = {
312312
...mockDevice,
313313
device_id: 'adguard_device_3',
314-
status: {
315-
...mockDevice.status,
314+
protection: {
315+
...mockDevice.protection,
316316
entity_id: 'binary_sensor.pi_hole_3_status',
317317
state: 'on',
318318
},
@@ -339,7 +339,7 @@ describe('pi-crust.ts', () => {
339339
const deviceWithoutStatus = {
340340
...mockDevice,
341341
device_id: 'adguard_device_2',
342-
status: undefined,
342+
protection: undefined,
343343
};
344344

345345
mockSetup.holes.push(deviceWithoutStatus);

0 commit comments

Comments
 (0)