(inputElement: HTMLInputElement, newValue: string, type: 'latitude' | 'longitude')
| 32 | } |
| 33 | |
| 34 | function locationChanged(inputElement: HTMLInputElement, newValue: string, type: 'latitude' | 'longitude') { |
| 35 | if (newValue.trim() === '') { |
| 36 | inputElement.value = ''; |
| 37 | |
| 38 | props.actions.changeSettings({ |
| 39 | location: { |
| 40 | ...locationSettings, |
| 41 | [type]: null, |
| 42 | }, |
| 43 | }); |
| 44 | |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | const min: number = values[type].min; |
| 49 | const max: number = values[type].max; |
| 50 | |
| 51 | newValue = newValue.replace(',', '.').replace('°', ''); |
| 52 | |
| 53 | let num = Number(newValue); |
| 54 | if (isNaN(num)) { |
| 55 | num = 0; |
| 56 | } else if (num > max) { |
| 57 | num = max; |
| 58 | } else if (num < min) { |
| 59 | num = min; |
| 60 | } |
| 61 | |
| 62 | inputElement.value = getLocationString(num); |
| 63 | |
| 64 | props.actions.changeSettings({ |
| 65 | location: { |
| 66 | ...locationSettings, |
| 67 | [type]: num, |
| 68 | }, |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | function changeAutomationMode(mode: Automation['mode']) { |
| 73 | props.actions.changeSettings({automation: {...props.data.settings.automation, ...{mode, enabled: Boolean(mode)}}}); |
no test coverage detected