-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add noise level to
NoiseSensorDeviceDetails
(#632)
* feat: Add noise level to Noise Sensor card * ci: Format code * Bump `seamapi` * Add `noiseaware_metadata` to seed * Add return type * Add return type (2) * ci: Format code * Satisfy linter boolean expression --------- Co-authored-by: Seam Bot <[email protected]>
- Loading branch information
Showing
5 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { NoiseSensorDevice } from 'seamapi' | ||
|
||
import { NoiseLevelsIcon } from 'lib/icons/NoiseLevels.js' | ||
|
||
interface NoiseLevelStatusProps { | ||
device: NoiseSensorDevice | ||
} | ||
|
||
export function NoiseLevelStatus({ | ||
device, | ||
}: NoiseLevelStatusProps): JSX.Element { | ||
return ( | ||
<> | ||
<span className='seam-label'>{t.noiseLevel}:</span> | ||
|
||
<div className='seam-device-status'> | ||
<NoiseLevelsIcon /> | ||
<span className='seam-text'>{getNoiseLevel(device)}</span> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
function toNoiseString(value: number | string | undefined): string { | ||
if (typeof value === 'string' || typeof value === 'number') { | ||
return `${Number(value).toFixed(0)} ${t.decibel}` | ||
} | ||
return t.unknown | ||
} | ||
|
||
function getNoiseLevel(device: NoiseSensorDevice): string { | ||
const isMinut = device.device_type === 'minut_sensor' | ||
const isNoiseAware = device.device_type === 'noiseaware_activity_zone' | ||
|
||
if (isMinut) { | ||
return toNoiseString( | ||
device?.properties?.minut_metadata?.latest_sensor_values?.sound?.value | ||
) | ||
} | ||
|
||
if (isNoiseAware) { | ||
if (device?.properties?.noiseaware_metadata?.noise_level_nrs === -1) { | ||
return t.noiseAwareDefault | ||
} | ||
return toNoiseString( | ||
device?.properties?.noiseaware_metadata?.noise_level_decibel | ||
) | ||
} | ||
|
||
return toNoiseString(undefined) | ||
} | ||
|
||
const t = { | ||
noiseLevel: 'Noise level', | ||
unknown: 'Unknown', | ||
decibel: 'dB', | ||
noiseAwareDefault: '0-40 dB', | ||
} |