Skip to content

Use PLATFORM_SCHEMA_BASE as base schema for additional components.#20578

Merged
balloob merged 3 commits into
home-assistant:devfrom
emontnemery:component_schema_various_2
Feb 5, 2019
Merged

Use PLATFORM_SCHEMA_BASE as base schema for additional components.#20578
balloob merged 3 commits into
home-assistant:devfrom
emontnemery:component_schema_various_2

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery commented Jan 29, 2019

Edit by @balloob: Breaking change should be listed in main release notes. Not just breaking changes section.


Description:

  • Use PLATFORM_SCHEMA_BASE as base schema for remaining components.
    PLATFORM_SCHEMA_BASE doesn't set extra=vol.ALLOW_EXTRA which means misspelled or unknown configuration variables will no longer be silently accepted.

  • Remove PLATFORM_SCHEMA_2 and remove extra=vol.ALLOW_EXTRA from PLATFORM_SCHEMA

#19871 should now be fixed.

This is a follow-up to #20224 .

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

@emontnemery emontnemery requested review from a team and fabaff as code owners January 29, 2019 18:57
@ghost ghost assigned emontnemery Jan 29, 2019
@ghost ghost added the in progress label Jan 29, 2019
"""Discover and add a MQTT camera."""
try:
discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH]
discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pop discovery_hash from the config dict since this is used by MQTT discovery, and not part of the schema.

"""Discover and add a MQTT climate device."""
try:
discovery_hash = discovery_payload[ATTR_DISCOVERY_HASH]
discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pop discovery_hash from the config dict since this is used by MQTT discovery, and not part of the schema.

default=DEFAULT_AWAY_TIMEOUT): cv.positive_int,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
})
}).extend(mqtt.MQTT_RO_PLATFORM_SCHEMA.schema)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform schema should extend standard MQTT schema which includes state_topic, qos, etc.

]

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_ENTITY_NAMESPACE): cv.string,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity_namespace is used in one of wunderground test cases.
Not sure if it's correct to add it here, or if the testcase is stale?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add it to the base platform schema. It's an option used in the entity component code, so all EntityPlatforms are affected.

Copy link
Copy Markdown
Contributor Author

@emontnemery emontnemery Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs:

These options are being phased out and are only available for single platform integrations.

But sure, maybe makes sense to add to the base schema.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but now we're talking about potentially breaking all platforms in one go. So it's needs to be a conscious decision.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fixed.

'method': 'GET',
'value_template': '{{ value_json.key }}',
'name': 'foo',
'unit_of_measurement': 'MB',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like test case copy/paste error

assert hass.states.get(DOMAIN + '.test').state == STATE_OPEN


async def test_disable_automatic_add(hass, monkeypatch):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

automatic_add is not supported for RFLink cover so remove the test.
@javicalle Maybe you can confirm it's correct to remove the test case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right
I have reviewed the cover component and it is as you say.
Sorry for the inconvenience.

'platform': 'mqtt',
'name': 'test',
'state_topic': 'test-topic',
'power_state_topic': 'test-topic',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/paste error.

'platform': 'mqtt',
'name': 'test',
'state_topic': 'test-topic',
'power_state_topic': 'test-topic',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/paste error.

'platform': 'filter',
'name': 'test',
'entity_id': 'sensor.test_monitored',
'history_period': '00:05',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No history_period configuration variable documented, copy/paste error?

)
for value in options:
cv.PLATFORM_SCHEMA(value)
cv.PLATFORM_SCHEMA_BASE(value)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about this one.
What's the point of this test case?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's that the base platform schema should require 'platform' key, and allow extra.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that makes sense.

@emontnemery emontnemery changed the title Use PLATFORM_SCHEMA_BASE as base schema for additional platforms. Use PLATFORM_SCHEMA_BASE as base schema for additional components. Jan 29, 2019
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked it over and it looks good besides the entity namespace key. We probably need to add that to PLATFORM_SCHEMA in config_validation.py.

@balloob should comment on that.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 30, 2019

Yeah, we should add it to the base schema validation.

@emontnemery
Copy link
Copy Markdown
Contributor Author

OK, fixed now.

I'm also a bit worried about breaking platforms which don't have tests and where configuration keys are missing from the schema. Maybe that simply has to be worked out in the beta cycle?

@MartinHjelmare
Copy link
Copy Markdown
Member

MartinHjelmare commented Jan 30, 2019

We should add a test for the entity namespace key, since it's a global option. Platform specific options aren't that dangerous. So I think it's ok to go ahead with this, after adding that test. We're hopefully improving config validation this way.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 31, 2019

Not having this go into the next release, 86 was a bit rough on config validation already.

@emontnemery
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare I'm really not sure how to write the new test..

As discussed on discord, this test tests entity_namespace but it just doesn't validate the config, so I think it's a start.

How to rewrite it to use async_setup_component though?

@emontnemery
Copy link
Copy Markdown
Contributor Author

emontnemery commented Feb 2, 2019

Test added which tests entity_namespace is in PLATFORM_SCHEMA

@MartinHjelmare
Copy link
Copy Markdown
Member

MartinHjelmare commented Feb 2, 2019

Should we separate entity namespace key addition to a separate PR that we include in 0.87, to avoid breaking any alarm_control_panel platforms?

@emontnemery
Copy link
Copy Markdown
Contributor Author

emontnemery commented Feb 2, 2019

@MartinHjelmare Good idea!

Edit: Done in #20693

@emontnemery emontnemery force-pushed the component_schema_various_2 branch 2 times, most recently from ffe2153 to 9fa549c Compare February 2, 2019 17:50
@emontnemery
Copy link
Copy Markdown
Contributor Author

@balloob

Not having this go into the next release, 86 was a bit rough on config validation already.

So can this be merged now that 0.87 beta is cut?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@balloob balloob merged commit b1faad0 into home-assistant:dev Feb 5, 2019
@ghost ghost removed the in progress label Feb 5, 2019
david-yam added a commit to david-yam/HeatPump that referenced this pull request Feb 8, 2019
Fix the configuration validation error issue due to Home Assistant disallow arbitrary configuration attributes in MQTT platforms.  See the issue log of HA for details: home-assistant/core#20578
@aidbish
Copy link
Copy Markdown
Contributor

aidbish commented Feb 11, 2019

Hi awesome dev folks,
Would it be prudent with this potentially breaking a lot of configs, to be a lot more visible in the release notes. The MQTT changes recently seem to have been missed by a fair few people from comments on the community pages/FB/reddit etc. Just a thought?

@MartinHjelmare
Copy link
Copy Markdown
Member

This hasn't been released yet.

@emontnemery
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare I think it's a request to make this change extra visible in the future 0.88 release notes, to increase the chance that users take notice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants