Skip to content

Add minimum/maximum to counter#20319

Closed
spacemanspiff2007 wants to merge 1 commit into
home-assistant:devfrom
spacemanspiff2007:dev
Closed

Add minimum/maximum to counter#20319
spacemanspiff2007 wants to merge 1 commit into
home-assistant:devfrom
spacemanspiff2007:dev

Conversation

@spacemanspiff2007
Copy link
Copy Markdown

@spacemanspiff2007 spacemanspiff2007 commented Jan 22, 2019

Docs: home-assistant/home-assistant.io#6802
OldPR: #17440

Description:

Example entry for configuration.yaml (if applicable):

counter:
  my_counter:
    initial: 0
    step : 1
    minimum: 0
    maximum: 10

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@dgomes
Copy link
Copy Markdown
Contributor

dgomes commented Jan 22, 2019

I know this to be a resubmittion of a PR that went wrong.

Still you need to reference the previous PR and add the proper description and reference to docs

@spacemanspiff2007
Copy link
Copy Markdown
Author

Updated description

@dgomes
Copy link
Copy Markdown
Contributor

dgomes commented Jan 22, 2019

Need to fix your code (tests aren't passing)

@rohankapoorcom
Copy link
Copy Markdown
Member

Looks like the test changes didn't make it into this one.

Copy link
Copy Markdown
Member

@rohankapoorcom rohankapoorcom left a comment

Choose a reason for hiding this comment

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

Added some thoughts, mostly stuff where the incorrect changes were applied on top of dev.

})
SERVICE_SCHEMA_SETUP = vol.Schema({
ATTR_ENTITY_ID: cv.entity_ids,
vol.Optional(CONF_MINIMUM): vol.Any(None, vol.Coerce(int)),
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.

Is it worth setting the defaults to max_int and min_int respectively? That way there's no need for None checking in check_boundaries.

})

CONFIG_SCHEMA = vol.Schema({
DOMAIN: cv.schema_with_slug_keys(
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.

This should not have changed.

SERVICE_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
SERVICE_SCHEMA_SIMPLE = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
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.

This should not have changed.

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'm also confused at how this could be optional in the first place. The docs agree: https://www.home-assistant.io/components/counter/.

Assuming it should not be optional, SERVICE_SCHEMA_SETUP should extend SERVICE_SCHEMA_SIMPLE which I would recommend renaming to SERVICE_SCHEMA_BASE

ret[CONF_MAXIMUM] = self._max
return ret

def __check_boundaries(self):
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.

It feels cleaner if this returns a true/false rather than making the change directly.

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.

And don't use double underscore in the beginning of the name. One underscore is enough.



class Counter(RestoreEntity):
class Counter(Entity):
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.

This should not have changed.

})
SERVICE_SCHEMA_SETUP = vol.Schema({
ATTR_ENTITY_ID: cv.entity_ids,
vol.Optional(CONF_MINIMUM): vol.Any(None, vol.Coerce(int)),
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.

It feels weird that these attributes are using CONF_ constants and not ATTR_ constants.

@MartinHjelmare MartinHjelmare changed the title added minimum/maximum to counter Add minimum/maximum to counter Feb 1, 2019
@rohankapoorcom
Copy link
Copy Markdown
Member

@spacemanspiff2007 are you going to be able to make these changes? I would love to get these features merged in (would be super useful to me!)

@spacemanspiff2007
Copy link
Copy Markdown
Author

Hi,
I am actually abroad for the next four weeks. After that I'll take a look and try again.

@robbiet480
Copy link
Copy Markdown
Contributor

@spacemanspiff2007 Closing this until you have time to get back to it. Feel free to reopen it once you do have the time!

@robbiet480 robbiet480 closed this Mar 25, 2019
@ghost ghost removed the in progress label Mar 25, 2019
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.

7 participants