From c4f56033e91c6d9499669ef919bcb7699ca597c3 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sat, 22 Apr 2023 18:51:10 +0200 Subject: [PATCH] Implement Config Flow Workday (#22907) Co-authored-by: Franck Nijhof --- source/_integrations/workday.markdown | 116 ++------------------------ 1 file changed, 8 insertions(+), 108 deletions(-) diff --git a/source/_integrations/workday.markdown b/source/_integrations/workday.markdown index f8f1a12b3ed..db41fed3a51 100644 --- a/source/_integrations/workday.markdown +++ b/source/_integrations/workday.markdown @@ -7,6 +7,7 @@ ha_category: ha_iot_class: Local Polling ha_release: 0.41 ha_quality_scale: internal +ha_config_flow: true ha_codeowners: - '@fabaff' - '@gjohansson-ST' @@ -25,127 +26,26 @@ This can be used to make automations that act differently on weekdays vs weekend Check the [country list](https://github.com/dr-prodigy/python-holidays#available-countries) for available provinces (and other subdivisions, like states and territories) for each country. -## Configuration -To enable the `workday` sensor in your installation, add the following to your `configuration.yaml` file: - -```yaml -# Example configuration.yaml entry -binary_sensor: - - platform: workday - country: DE -``` - -{% configuration %} -name: - description: A name for this sensor. - required: false - type: string - default: Workday Sensor -country: - description: > - Country code according to [holidays](https://pypi.org/project/holidays/) notation. - required: true - type: string -province: - description: Subdivision code according to [holidays](https://pypi.org/project/holidays/) notation. - required: false - type: string -workdays: - description: List of workdays. - required: false - type: list - default: "[mon, tue, wed, thu, fri]" -excludes: - description: List of workday excludes. - required: false - type: list - default: "[sat, sun, holiday]" -days_offset: - description: Set days offset (e.g., -1 for yesterday, 1 for tomorrow). - required: false - type: integer - default: 0 -add_holidays: - description: "Add custom holidays (such as company, personal holidays or vacations). Needs to formatted as `YYYY-MM-DD`." - required: false - type: list -remove_holidays: - description: "Remove holidays (treat holiday as workday). Can be formatted as `YYYY-MM-DD` or by name for a partial string match (e.g. Thanksgiving)." - required: false - type: list -{% endconfiguration %} +{% include integrations/config_flow.md %} Days are specified as follows: `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun`. The keyword `holiday` is used for public holidays identified by the holidays module.
-If you use the sensor for Norway (`NO`) you need to wrap `NO` in quotes or write the name in full. -Otherwise, the value is evaluated as `false`. -If you use the sensor for Canada (`CA`) with Ontario (`ON`) as `province:` then you need to wrap `ON` in quotes. -Otherwise, the value is evaluated as `true` (check the YAML documentation for further details) and the sensor will not work. - -One other thing to watch is how the `holiday` keyword is used. Your first instinct might be to add it to the `exclude` configuration, thinking that it means to skip the holidays. Actually it means to exclude the days in the holidays list from the workdays. So, when you exclude `holiday` and a workday falls on that day, then that workday is excluded, and the sensor will be **off**. If you want every workday flagged with no regard to holidays, make sure that there is something in your `Excludes` configuration _other_ than `holiday`. +Watch how the `holiday` keyword is used. Your first instinct might be adding it to the `exclude` configuration, thinking it means skipping the holidays. It means to exclude the days in the holiday list from the workdays. So, when you exclude `holiday` and a workday falls on that day, that workday is excluded, and the sensor will be **off**. If you want every workday flagged with no regard to holidays, ensure that there is something in your `Excludes` configuration _other_ than `holiday`.
-## Full examples +## Specific field information -This example excludes Saturdays and Sundays but not pre-configured holidays. Two custom holidays are added. +Country code must be given according to [holidays](https://pypi.org/project/holidays/) notation. -```yaml -# Example 1 configuration.yaml entry -binary_sensor: - - platform: workday - country: US - workdays: [mon, tue, wed, thu, fri] - excludes: [sat, sun] - add_holidays: - - "2020-02-24" - - "2020-04-25" -``` +Subdivision code must be given according to [holidays](https://pypi.org/project/holidays/) notation. -This example excludes Saturdays, Sundays and holidays. One custom holiday is added. -The date February 24th, 2020 is a Monday, but will be excluded (the sensor will be **off**) because it was added to the `add_holidays` configuration. +Add holidays will only take dates formatted with `YYYY-MM-DD`. -```yaml -# Example 2 configuration.yaml entry -binary_sensor: - - platform: workday - country: DE - workdays: [mon, tue, wed, thu, fri] - excludes: [sat, sun, holiday] - add_holidays: - - '2020-02-24' -``` - -This example excludes Saturdays, Sundays and holidays. Two holidays are removed: November 26, 2020 and December 25, 2020. - -```yaml -# Example 3 configuration.yaml entry -binary_sensor: - - platform: workday - country: US - workdays: [mon, tue, wed, thu, fri] - excludes: [sat, sun, holiday] - remove_holidays: - - '2020-11-26' - - '2020-12-25' -``` - -This example excludes Saturdays, Sundays and holidays. Two holidays are removed by name: Thanksgiving and Christmas Day. - -```yaml -# Example 4 configuration.yaml entry -binary_sensor: - - platform: workday - country: US - workdays: [mon, tue, wed, thu, fri] - excludes: [sat, sun, holiday] - remove_holidays: - - 'Thanksgiving' - - 'Christmas Day' -``` +Remove holidays will take dates formatted with `YYYY-MM-DD` or partial of name, for example, `christmas` will exclude `Christmas Day`. ## Automation example