Commit Graph

114 Commits (999eeb39b919b4549fd912d4b2d311c634f48bf3)

Author SHA1 Message Date
Penny Wood 5b9d01139d
render_with_collect method for template (#23283)
* Make entity_filter be a modifiable builder

* Add render_with_collect method

* Use sync render_with_collect and non-class based test case

* Refactor: Template renders to RenderInfo

* Freeze with exception too

* Finish merging test changes

* Removed unused sync interface

* Final bits of the diff
2019-05-01 10:54:25 +08:00
Moritz Fey f272ed3b91 Add 'method' parameter to forgiving_round method (#21708)
* Add 'method' parameter to forgiving_round method

Fixes #21707

* fix rounding behavior in round() filter

* add test cases for new rounding behaviour
2019-03-24 18:10:49 -07:00
Brad Dixon 9ab543ab3d Add as_timestamp() to Jinja filters. (#21910)
Add as_timestamp() to Jinja filters
2019-03-11 13:21:22 +05:30
Phil Bruckner 935e5c67a3 Handle non-string values in JSON renderer (#20233)
Handle the case of async_render_with_possible_json_value's value argument
being something other than a string. This can happen, e.g., when using the
SQL sensor to extract a datetime column such as last_changed and also using
its value_template to convert that datetime to another format. This was
causing a TypeError from json.loads, but async_render_with_possible_json_value
was only catching ValueError's.
2019-01-20 16:46:14 -08:00
Ville Skyttä 58bb6f2e99 Add type hints to helpers.condition (#20266) 2019-01-21 00:03:12 +01:00
emontnemery b97f0c0261 Make variable `entity_id` available to value_template for MQTT binary sensor (#19195)
* MQTT binary_sensor: Make variable `entity_id` available to value_template

* Review comments

* Add testcase
2018-12-14 13:00:37 +01:00
emontnemery bbb40fde84 Optionally do not log template rendering errors (#18724) 2018-12-02 10:31:46 +01:00
Joakim Sørensen 558504c686 Fix ordinal filter in template (#18878) 2018-12-01 14:49:34 +01:00
Mahasri Kalavala c23792d1fb Added new filters for templates (#18125)
* added additional filters

Added base64_encode, base64_decode and ordinal filters.

* added test cases

added test cases for base64_encode, base64_decode and ordinal filters.

* forgot to add filters :)
2018-12-01 10:38:10 +01:00
Neil Crosby 865ea82432 Allow jinja namespace command to work. (#18011) 2018-10-30 19:13:20 +01:00
Anders Melchiorsen 3de822a0e2 RFC: Static templates match no entities, not all (#17991)
* Static templates match no entities, not all

* Clean up test values
2018-10-30 12:03:27 +01:00
Markus Nigbur 670c75e844 Added resolve_state to template distance function (#17290)
_resolve_state was already used in the "closest" function, to allow for states and entity ids
2018-10-10 11:49:24 +02:00
Blake Blackshear f13f723a04 Add bitwise operations as template helpers (#16833) 2018-09-26 11:57:16 +02:00
Ville Skyttä 3246b49a45 Upgrade pylint to 2.1.0 (#15811)
* Upgrade pylint to 2.1.0

* Remove no longer needed pylint disables
2018-08-04 15:22:22 +02:00
Ville Skyttä b7c336a687 Pylint cleanups (#15626)
* Pylint 2 no-else-return fixes

* Remove unneeded abstract-class-not-used pylint disable
2018-07-23 10:16:05 +02:00
Ville Skyttä 2f7b79764a More pylint 2 fixes (#15565)
## Description:

More fixes flagged by pylint 2 that don't hurt to have before the actual pylint 2 upgrade (which I'll submit soon).

## Checklist:
  - [ ] The code change is tested and works locally.
  - [x] Local tests pass with `tox`. **Your PR cannot be merged unless tests pass**
2018-07-20 11:45:20 +03:00
Paulus Schoutsen 83d300fd11 Custom component loading cleanup (#14211)
* Clean up custom component loading

* Fix some tests

* Fix some stuff

* Make imports work again

* Fix tests

* Remove debug print

* Lint
2018-05-01 20:57:30 +02:00
Benedict Aas 9677bc081e Add more math functions to templates (#13915)
We make `sin`, `cos`, `tan`, and `sqrt` functions, and the `pi`, `tau`,
and `e` constants available in templates.
2018-04-15 18:51:45 +02:00
mountainsandcode 032d6963d8 Add regex functions as templating helpers (#13631)
* Add regex functions as templating helpers

* Add regex functions as templating helpers - Style fixed

* Templating filters, third time lucky?
2018-04-04 15:34:01 +02:00
Mikael Svensson bdb4d754ae Adds template function state_attr to get attribute from a state (#13378)
* Adds template function state_attr to get attribute from a state
Refactored is_state_attr to use new function
Adds tests for state_attr

* Fixes line too long and test bug

* Fixes pylint error

* Fixes tests and D401 lint error
2018-03-28 00:04:18 -07:00
Anders Melchiorsen 55daea5169 Improve detection of entity names in templates (#13432)
* Improve detection of entity names in templates

* Only test variables
2018-03-25 12:51:11 +02:00
Matthias Urlichs f5cc40024d Rename homeassistant.util.async to .async_ (#13088)
"async" is (going to be) a reserved word.
2018-03-11 10:01:12 -07:00
Otto Winter 678f284015 Upgrade pylint to 1.8.2 (#12274)
* Upgrade pylint to 1.8.1

* Fix no-else-return

* Fix bad-whitespace

* Fix too-many-nested-blocks

* Fix raising-format-tuple

See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst

* Fix len-as-condition

* Fix logging-not-lazy

Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string

* Fix stop-iteration-return

* Fix useless-super-delegation

* Fix trailing-comma-tuple

Both of these seem to simply be bugs:
 * Nest: The value of self._humidity never seems to be used anywhere
 * Dovado: The called API method seems to expect a "normal" number

* Fix redefined-argument-from-local

* Fix consider-using-enumerate

* Fix wrong-import-order

* Fix arguments-differ

* Fix missed no-else-return

* Fix no-member and related

* Fix signatures-differ

* Revert "Upgrade pylint to 1.8.1"

This reverts commit af78aa00f125a7d34add97b9d50c14db48412211.

* Fix arguments-differ

* except for device_tracker

* Cleanup

* Fix test using positional argument

* Fix line too long

I forgot to run flake8 - shame on me... 🙃

* Fix bad-option-value for 1.6.5

* Fix arguments-differ for device_tracker

* Upgrade pylint to 1.8.2

* 👕 Fix missed no-member
2018-02-11 09:20:28 -08:00
Otto Winter 8dcfd35b8b Spelling fixes (#12041)
* Spelling fixes

*Lots* of them.

* Spelling breaking changes

* Fix lint errors
2018-01-29 23:37:19 +01:00
Fabian Affolter 47e31dc9ee Fixes for PEP257 (#11810)
* Fixes for PEP257

* More updates
2018-01-20 22:35:38 -08:00
tschmidty69 48619c9d7c Implemented event_data_template (new) (#11057)
* Implemented event_data_template

* The hound does not like my indentation

* Added passed variables to tests for event and svc template calls

* Moved recursive function to template.py

* Update template.py

* Update template.py

* Cleaned up service.py and fixed unit tests

* Blank lines

* Removed stray logger statement

* Blank lines again
2018-01-18 22:13:14 -08:00
Odin Ugedal 0668fba7bd Add support for logarithm in templates (#10824)
* Add support for logarithm in templates

This adds a 'log' filter that takes the logarithm of the given value,
with an optional base number. The base defaults to 'e' - the natural
logarithm

* Remove usage of log10 in template filter 'log'

* Add logarithm as a global

This makes it possible to write:
'{{ log(4, 2) }}'
2017-11-27 21:29:01 -08:00
Paulus Schoutsen 4e8e04fe66 Clean up core (#10305)
* Clean up core

* Lint

* Fix tests

* Address comment

* Update entity.py

* romve test for forward update to async_update

* fix lint
2017-11-03 14:19:36 +01:00
cdce8p be5c0b2d92 Wait_template - support for 'trigger.entity_id' and data_template values (#9807)
* *Added support for use of 'trigger.entity_id' and service->data_template->script in wait_template

* * Fixed style violations

* * Fixed regular expression (_RE_GET_POSSIBLE_ENTITIES)

* * combined 'extract_entities' and 'extract_entities_with_variables'
* fixed regular expression

* * Added first test for extract_entities_with_variables

* * Added Unittests (tests/helpers/test_template.py test_extract_entities_with_variables)

* * Added Unittests (tests/helpers/test_script.py test_wait_template_variables)

* * Added Unittests (tests/components/automation/test_template.py test_wait_template_with_trigger)

* * Added Unittests (tests/components/automation/test_state.py test_wait_template_with_trigger)

* * Added Unittests (tests/components/automation/test_numeric_state.py test_wait_template_with_trigger)

* * Fixed style violations

* * Fixed style violations

* * Fixed style violations

* * Fixed style violations

* * Fixed style violations

* * Fixed style violations

* * Updated regular expression and delete whitespaces
2017-10-12 16:57:18 +02:00
Paulus Schoutsen ca54bbfcc9 RFC: Use bind_hass for helpers (#9745)
* Add Helpers bind_hass functionality

* Update other helpers
2017-10-08 08:17:54 -07:00
Paulus Schoutsen 5629157740 Allow getting number of available states in template (#9158) 2017-08-27 18:33:25 +02:00
Paulus Schoutsen 8605098ea0 Wrap state when iterating a domain in templates (#9157) 2017-08-26 17:00:59 -07:00
Paulus Schoutsen b282167f26 Add state_with_unit property to state objects in templates (#9014)
* Wrap state objects in templates

* Fix tests

* Fix bugs

* Lint

* Remove invalid state warning
2017-08-17 23:19:35 -07:00
Paulus Schoutsen 5779d64e98 Fix some issues for PyLint 1.7.2 (#8356)
* Fix some issues for PyLint 1.7.2

* More fixes

* Revert position change for cover
2017-07-05 20:02:16 -07:00
Anton Sarukhanov f3dabe21ab Prevent the random template filter from caching its output. Fixes #5678 (#7716) 2017-05-23 10:32:06 -07:00
Fabian Affolter 4d52b0ecd5 Update docstrings (#7405)
* Update docstrings

* Fix lint issues

* Update docstrings
2017-05-02 22:47:20 +02:00
Fabian Affolter a4f1f6e724 Update docstrings (#7374)
* Update docstrings

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstrings

* Update docstring

* Update docstrings

* Update docstrings

* Fix lint issues

* Update docstrings

* Revert changes in dict
2017-05-02 09:18:47 -07:00
Fabian Affolter cfc023e128 Don't use len(SEQUENCE) as condition value (#7249)
* Don't use len(SEQUENCE) as condition value

* Update volvooncall.py
2017-04-23 20:41:09 -07:00
Jose Juan Montes 4da2156ebf Return None instead of raising ValueException from as_timestamp template function. (#6155) 2017-03-02 22:18:01 -08:00
Stéphane Bidoul (ACSONE) 7927a6b588 add min and max jinja filters (#5765) 2017-02-07 00:25:47 -08:00
Paulus Schoutsen d2bbc6ef70 Upgrade linter (#4461) 2016-11-18 21:47:59 -08:00
Lewis Juggins 01a6c1c1c8 Add strptime template function (#3950) 2016-11-10 22:57:44 -08:00
Fabian Affolter be272ac64a Disable too-many-* (#4107)
* Disable too-many-* and too-few-public-methods

* Remove globally disabled pylint warnings
2016-10-30 22:18:53 +01:00
Jan Harkes 118f2f0bad Use a filter to fail rendering undefined variables
Instead of globally using StrictUndefined, introduce a filter that
will trigger a render failure on undefined variables.

Use as `{{ value_json.someval | is_defined }}`.
2016-10-17 03:20:07 +02:00
Jan Harkes c8add59ea5 Fail when rendering undefined objects in Jinja2 templates
By not successfully rendering unknown objects to an empty string
the caller provided error_value actually gets used.

This allows, for instance, the MQTT sensor to retain its state when an
unexpected or unwanted message (#2733/#3834) is received.
2016-10-17 03:20:07 +02:00
Paulus Schoutsen 412b5350ce Service config calls will no longer mutate original config (#3628) 2016-09-30 23:26:15 -07:00
Paulus Schoutsen b650b2b0db Spread async love (#3575)
* Convert Entity.update_ha_state to be async

* Make Service.call async

* Update entity.py

* Add Entity.async_update

* Make automation zone trigger async

* Fix linting

* Reduce flakiness in hass.block_till_done

* Make automation.numeric_state async

* Make mqtt.subscribe async

* Make automation.mqtt async

* Make automation.time async

* Make automation.sun async

* Add async_track_point_in_utc_time

* Make helpers.track_sunrise/set async

* Add async_track_state_change

* Make automation.state async

* Clean up helpers/entity.py tests

* Lint

* Lint

* Core.is_state and Core.is_state_attr are async friendly

* Lint

* Lint
2016-09-30 12:57:24 -07:00
Paulus Schoutsen 00e298206e Optimize template 2 (#3521)
* Enforce compiling templates

* Refactor templates

* Add template validator to Logbook service

* Some more fixes

* Lint

* Allow easy skipping of rfxtrx tests

* Fix template bug in AND & OR conditions

* add entities extractor

Conflicts:
	tests/helpers/test_template.py

* fix unittest

* Convert template to be async

* Fix Farcy

* Lint fix

* Limit template updates to related entities

* Make template automation async
2016-09-27 21:29:55 -07:00
Paulus Schoutsen 0c0feda834 Pre-compile templates (#3515)
* Pre-compile templates

* Compile templates in numeric_state condition
2016-09-25 13:33:01 -07:00
Lewis Juggins 44f5a66b66 Add additional template for custom date formats (#3262)
I can live with a few visual line breaks 🐬
2016-09-08 18:49:02 -06:00
Paulus Schoutsen 35b388edce Reload groups (#3203)
* Allow reloading groups without restart

* Test to make sure automation listeners are removed.

* Remove unused imports for group tests

* Simplify group config validation

* Add prepare_reload function to entity component

* Migrate group to use entity_component.prepare_reload

* Migrate automation to use entity_component.prepare_reload

* Clean up group.get_entity_ids

* Use cv.boolean for group config validation
2016-09-07 06:59:16 -07:00
Teagan M. Glenn 26526ca57a Add unit system support
Add unit symbol constants

Initial unit system object

Import more constants

Pydoc for unit system file

Import constants for configuration validation

Unit system validation method

Typing for constants

Inches are valid lengths too

Typings

Change base class to dict - needed for remote api call serialization

Validation

Use dictionary keys

Defined unit systems

Update location util to use metric instead of us fahrenheit

Update constant imports

Import defined unit systems

Update configuration to use unit system

Update schema to use unit system

Update constants

Add imports to core for unit system and distance

Type for config

Default unit system

Convert distance from HASS instance

Update temperature conversion to use unit system

Update temperature conversion

Set unit system based on configuration

Set info unit system

Return unit system dictionary with config dictionary

Auto discover unit system

Update location test for use metric

Update forecast unit system

Update mold indicator unit system

Update thermostat unit system

Update thermostat demo test

Unit tests around unit system

Update test common hass configuration

Update configuration unit tests

There should always be a unit system!

Update core unit tests

Constants typing

Linting issues

Remove unused import

Update fitbit sensor to use application unit system

Update google travel time to use application unit system

Update configuration example

Update dht sensor

Update DHT temperature conversion to use the utility function

Update swagger config

Update my sensors metric flag

Update hvac component temperature conversion

HVAC conversion for temperature

Pull unit from sensor type map

Pull unit from sensor type map

Update the temper sensor unit

Update yWeather sensor unit

Update hvac demo unit test

Set unit test config unit system to metric

Use hass unit system length for default in proximity

Use the name of the system instead of temperature

Use constants from const

Unused import

Forecasted temperature

Fix calculation in case furthest distance is greater than 1000000 units

Remove unneeded constants

Set default length to km or miles

Use constants

Linting doesn't like importing just for typing

Fix reference

Test is expecting meters - set config to meters

Use constant

Use constant

PyDoc for unit test

Should be not in

Rename to units

Change unit system to be an object - not a dictionary

Return tuple in conversion

Move convert to temperature util

Temperature conversion is now in unit system

Update imports

Rename to units

Units is now an object

Use temperature util conversion

Unit system is now an object

Validate and convert unit system config

Return the scalar value in template distance

Test is expecting meters

Update unit tests around unit system

Distance util returns tuple

Fix location info test

Set units

Update unit tests

Convert distance

DOH

Pull out the scalar from the vector

Linting

I really hate python linting

Linting again

BLARG

Unit test documentation

Unit test around is metric flag

Break ternary statement into if/else blocks

Don't use dictionary - use members

is metric flag

Rename constants

Use is metric flag

Move constants to CONST file

Move to const file

Raise error if unit is not expected

Typing

No need to return unit since only performing conversion if it can work

Use constants

Line wrapping

Raise error if invalid value

Remove subscripts from conversion as they are no longer returned as tuples

No longer tuples

No longer tuples

Check for numeric type

Fix string format to use correct variable

Typing

Assert errors raised

Remove subscript

Only convert temperature if we know the unit

If no unit of measurement set - default to HASS config

Convert only if we know the unit

Remove subscription

Fix not in clause

Linting fixes

Wants a boolean

Clearer if-block

Check if the key is in the config first

Missed a couple expecting tuples

Backwards compatibility

No like-y ternary!

Error handling around state setting

Pretty unit system configuration validation

More tuple crap

Use is metric flag

Error handling around min/max temp

Explode if no unit

Pull unit from config

Celsius has a decimal

Unused import

Check if it's a temperature before we try to convert it to a temperature

Linting says too many statements - combine lat/long in a fairly reasonable manner

Backwards compatibility unit test

Better doc
2016-08-04 22:02:19 -07:00
Fabian Affolter 57c2dea02d Add timestamp filters (#2596) 2016-07-22 19:47:43 -07:00
Robbie Trencheny 4d0b9f1e94 Stupid blank lines 2016-05-11 22:44:44 -07:00
Robbie Trencheny fca4ec2b3e simplify the relative_time function 2016-05-11 22:37:37 -07:00
Robbie Trencheny 16933abce9 Remove humanize and use a relative time thing that @balloob found on Github 2016-05-10 00:04:53 -07:00
Robbie Trencheny d5a1c52359 Add a Jinja filter for relative time 2016-05-09 23:31:02 -07:00
Charles Spirakis b86a1ece01 Allow conversion from date strings to "unix" timestamp. (#1985)
"unix" timestamp is number of seconds since Jan 1, 1970 UTC.
This allows scripts that use templates to generate time
deltas in seconds if desired from state attributes such
as last_updated.

Some examples:

timestamp now is
{{ as_timestamp(now) }}

timstamp of last change is
{{ as_timestamp(states.binary_sensor.garage_door.last_changed) }}

seconds since last change is
{{ as_timestamp(now) - as_timestamp(states.binary_sensor.garage_door.last_changed) }}
2016-05-06 18:33:46 -07:00
Paulus Schoutsen 6354399d55 Initial script condition support (#1910) 2016-04-28 12:03:57 +02:00
Fabian Affolter f22a40c3e8 Fix PEP257 issues 2016-03-09 11:15:04 +01:00
Fabian Affolter 4f536ac63d Fix PEP257 issues 2016-03-07 23:39:52 +01:00
Dan Smith db4bf7319f Add float() operator to templates 2016-02-24 20:07:46 -08:00
Fabian Affolter 582394bc3b Modify import of template and PEP257 2016-02-23 21:19:22 +01:00
Fabian Affolter 213cc920d0 Move template to helpers 2016-02-23 21:19:10 +01:00