Skip to content

Commit

Permalink
Merge pull request PiotrMachowski#176 from PiotrMachowski/dev
Browse files Browse the repository at this point in the history
v2.0.2
  • Loading branch information
PiotrMachowski authored Nov 18, 2021
2 parents 6c9492d + af97ded commit 9224dca
Show file tree
Hide file tree
Showing 31 changed files with 1,442 additions and 171 deletions.
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = {
tabWidth: 4,
bracketSameLine: true,
arrowParens: "avoid",
endOfLine: "crlf",
};
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v2.0.1",
"version": "v2.0.2",
"tasks": [
{
"type": "npm",
Expand Down
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ You can use this configuration as an example: [demo config](/docs/demo_config.ya
<td><i>empty</i></td>
<td>Card's title</td>
</tr>
<tr>
<td><code>language</code></td>
<td>string</td>
<td>no</td>
<td><i>autodetected</i></td>
<td>Overrides autodetected language (<a href="#translations">supported languages</a>)</td>
</tr>
<tr>
<td><code>additional_presets</code></td>
<td>list</td>
Expand All @@ -167,7 +174,9 @@ You can use this configuration as an example: [demo config](/docs/demo_config.ya
| `map_locked` | boolean | no | `false` | Default state of pan/zoom |
| `two_finger_pan` | string | no | `false` | Enables two finger map panning |
| `icons` | list | no | _autogenerated_ | Preset's [icons](#icon-list-entry-options) |
| `append_icons` | boolean | no | `false` | Enables appending configured icons to autogenerated ones instead of replacing them |
| `tiles` | list | no | _autogenerated_ | Preset's [tiles](#tile-list-entry-options) |
| `append_tiles` | boolean | no | `false` | Enables appending configured tiles to autogenerated ones instead of replacing them |
| `map_modes` | list | no | _autogenerated_ | Preset's [map modes](#map-modes-options) |

### Map source options
Expand Down Expand Up @@ -219,6 +228,7 @@ map: # coordinates of a point in a map coordinate system (can be read using e.g.
Following vacuum platforms are supported at this moment:
- `default`: [Built-in Home Assistant integration](https://www.home-assistant.io/integrations/xiaomi_miio/#xiaomi-mi-robot-vacuum)
- `KrzysztofHajdamowicz/miio2`: [Custom miio2 integration by Krzysztof Hajdamowicz](https://github.com/KrzysztofHajdamowicz/home-assistant-vacuum-styj02ym)
- `send_command`: Uses `vacuum.send_command` service with commands: `app_zoned_clean`, `app_goto_target`, `app_segment_clean`

[Adding a new platform](CONTRIBUTING.md#adding-new-platform)

Expand All @@ -233,6 +243,7 @@ Following vacuum platforms are supported at this moment:
| `hold_action` | action | no | - | [Action](https://www.home-assistant.io/lovelace/actions) that will be triggered when an icon is held and released |
| `double_tap_action` | action | no | - | [Action](https://www.home-assistant.io/lovelace/actions) that will be triggered when an icon is double-tapped |
| `conditions` | list | no | - | List of [conditions](#condition-options) that need to be (all of them) met for an icon to be shown |
| `tooltip` | string | false | - | Tooltip to be displayed on hoover |

### Tile list entry options

Expand All @@ -251,6 +262,7 @@ Following vacuum platforms are supported at this moment:
| `hold_action` | action | no | - | [Action](https://www.home-assistant.io/lovelace/actions) that will be triggered when a tile is held and released |
| `double_tap_action` | action | no | - | [Action](https://www.home-assistant.io/lovelace/actions) that will be triggered when a tile is double-tapped |
| `conditions` | list | no | - | List of [conditions](#condition-options) that need to be (all of them) met for a tile to be shown |
| `tooltip` | string | false | - | Tooltip to be displayed on hoover |

### Condition options

Expand Down Expand Up @@ -305,6 +317,13 @@ List of supported templates depends on selected `vacuum_platform`:
- `vacuum_goto_predefined`: Point selected on the map from `predefined_selections`
- `vacuum_clean_segment`: Identifier-based selection with free-drawn outline
- `vacuum_follow_path`: Path selected by clicking on the map (using [script](/docs/follow_path.yaml))
- `send_command`
- `vacuum_clean_zone`: Free-drawn rectangular zones on the map
- `vacuum_clean_zone_predefined`: Rectangular zones that can be selected on the map from `predefined_selections`
- `vacuum_goto`: Point selected by clicking in an arbitrary place on the map
- `vacuum_goto_predefined`: Point selected on the map from `predefined_selections`
- `vacuum_clean_segment`: Identifier-based selection with free-drawn outline
- `vacuum_follow_path`: Path selected by clicking on the map (using [script](/docs/follow_path.yaml))

> See [hints](#hints) to check how to easily retrieve zone/point coordinates.

Expand Down Expand Up @@ -418,7 +437,6 @@ Format of data depends on selected `selection_type`:
| `name` | string | yes | - | An icon to be displayed ([mdi](https://materialdesignicons.com/)) |
| `x` | number | yes | - | X coordinate of an icon (in vacuum's coordinate system) |
| `y` | number | yes | - | Y coordinate of an icon (in vacuum's coordinate system) |
| `tooltip` | string | false | - | Tooltip to be displayed on hoover |

#### Label options

Expand All @@ -427,7 +445,6 @@ Format of data depends on selected `selection_type`:
| `text` | string | yes | - | Text to be displayed |
| `x` | number | yes | - | X coordinate of a label (in vacuum's coordinate system) |
| `y` | number | yes | - | Y coordinate of a label (in vacuum's coordinate system) |
| `tooltip` | string | false | - | Tooltip to be displayed on hoover |
| `offset_x` | number | no | - | Offset that should be applied to label in X direction (in pixels) |
| `offset_y` | number | no | - | Offset that should be applied to label in Y direction (in pixels) |

Expand Down Expand Up @@ -614,15 +631,21 @@ map_modes:
## Translations

Currently, this card contains translations for following languages:
* English
* Polish (Polski)
* `en` - English
* `es` - Spanish (Español)
* `fr` - French (Français)
* `it` - Italian (Italiano)
* `pl` - Polish (Polski)
* `pt-BR` - Brazilian Portuguese (Português Brasileiro)
* `ru` - Russian (Русский)
* `uk` - Ukrainian (Українська)

[Adding a new language](CONTRIBUTING.md#adding-new-translations)

## Special thanks

I'd like to give special thanks to people who helped me with card's design and development:
* [Bartosz Orczyk](www.bratver.com)
* [Bartosz Orczyk](www.bratver.com)
* [Filip Schramm](https://github.com/fi-sch)
* [Kamil Dryzek](https://github.com/dryzek)
* [Marek Trochimiak](https://github.com/tromarek1)
Expand Down
6 changes: 3 additions & 3 deletions docs/css_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
--map-card-ripple-color
--map-card-big-radius
--map-card-small-radius
--map-card-predefined-point-icon-wrapper-size
--map-card-predefined-point-icon-size
--map-card-predefined-point-icon-padding
--map-card-predefined-point-icon-color
--map-card-predefined-point-icon-color-selected
--map-card-predefined-point-icon-background-color
Expand All @@ -36,8 +36,8 @@
--map-card-predefined-rectangle-fill-color-selected
--map-card-predefined-rectangle-line-segment-line
--map-card-predefined-rectangle-line-segment-gap
--map-card-predefined-rectangle-icon-wrapper-size
--map-card-predefined-rectangle-icon-size
--map-card-predefined-rectangle-icon-padding
--map-card-predefined-rectangle-icon-color
--map-card-predefined-rectangle-icon-color-selected
--map-card-predefined-rectangle-icon-background-color
Expand Down Expand Up @@ -79,8 +79,8 @@
--map-card-room-outline-fill-color
--map-card-room-outline-line-color-selected
--map-card-room-outline-fill-color-selected
--map-card-room-icon-wrapper-size
--map-card-room-icon-size
--map-card-room-icon-padding
--map-card-room-icon-color
--map-card-room-icon-color-selected
--map-card-room-icon-background-color
Expand Down
10 changes: 8 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xiaomi-vacuum-map-card",
"version": "v2.0.1",
"version": "v2.0.2",
"description": "Xiaomi Vacuum Map Card",
"keywords": [
"home-assistant",
Expand Down
25 changes: 17 additions & 8 deletions src/config-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IconActionConfig,
IconConfig,
LabelConfig,
Language,
MapModeConfig,
MapSourceConfig,
PredefinedPointConfig,
Expand All @@ -18,7 +19,7 @@ import {
TranslatableString,
XiaomiVacuumMapCardConfig,
} from "./types/types";
import { localizeTranslatable } from "./localize/localize";
import { localize } from "./localize/localize";
import { MapMode } from "./model/map_mode/map-mode";
import { SelectionType } from "./model/map_mode/selection-type";
import { PlatformGenerator } from "./model/generators/platform-generator";
Expand Down Expand Up @@ -182,7 +183,11 @@ function validateServiceCallSchemaConfig(config: ServiceCallSchemaConfig): Trans
return [];
}

function validateMapModeConfig(vacuumPlatform: string, config: MapModeConfig): TranslatableString[] {
function validateMapModeConfig(
vacuumPlatform: string,
config: MapModeConfig,
language: Language,
): TranslatableString[] {
if (!config) {
return ["validation.preset.map_modes.invalid"];
}
Expand All @@ -199,7 +204,7 @@ function validateMapModeConfig(vacuumPlatform: string, config: MapModeConfig): T
if (!config.template && !config.service_call_schema) {
errors.push("validation.preset.map_modes.service_call_schema.missing");
}
const parsed = new MapMode(vacuumPlatform, config);
const parsed = new MapMode(vacuumPlatform, config, language);
switch (parsed.selectionType) {
case SelectionType.PREDEFINED_RECTANGLE:
parsed.predefinedSelections
Expand Down Expand Up @@ -228,7 +233,7 @@ function validateMapModeConfig(vacuumPlatform: string, config: MapModeConfig): T
return errors;
}

function validatePreset(config: CardPresetConfig, nameRequired: boolean): TranslatableString[] {
function validatePreset(config: CardPresetConfig, nameRequired: boolean, language: Language): TranslatableString[] {
const errors: TranslatableString[] = [];
const mandatoryFields = new Map<string, string>([
["entity", "validation.preset.entity.missing"],
Expand All @@ -248,17 +253,21 @@ function validatePreset(config: CardPresetConfig, nameRequired: boolean): Transl
const vacuumPlatform = config.vacuum_platform ?? "default";
(config.icons ?? []).flatMap(i => validateIconConfig(i)).forEach(e => errors.push(e));
(config.tiles ?? []).flatMap(i => validateSensorConfig(i)).forEach(e => errors.push(e));
(config.map_modes ?? []).flatMap(i => validateMapModeConfig(vacuumPlatform, i)).forEach(e => errors.push(e));
(config.map_modes ?? [])
.flatMap(i => validateMapModeConfig(vacuumPlatform, i, language))
.forEach(e => errors.push(e));
if (!config.preset_name && nameRequired) errors.push("validation.preset.preset_name.missing");
return errors;
}

export function validateConfig(config: XiaomiVacuumMapCardConfig): string[] {
const errors: TranslatableString[] = [];
const multiplePresets = (config.additional_presets?.length ?? 0) > 0;
validatePreset(config, multiplePresets).forEach(e => errors.push(e));
config.additional_presets?.flatMap(preset => validatePreset(preset, multiplePresets)).forEach(e => errors.push(e));
return errors.map(e => localizeTranslatable(e));
validatePreset(config, multiplePresets, config.language).forEach(e => errors.push(e));
config.additional_presets
?.flatMap(preset => validatePreset(preset, multiplePresets, config.language))
.forEach(e => errors.push(e));
return errors.map(e => localize(e, config.language));
}

export function isOldConfig(config: XiaomiVacuumMapCardConfig): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const CARD_VERSION = "v2.0.1";
export const CARD_VERSION = "v2.0.2";
Loading

0 comments on commit 9224dca

Please sign in to comment.