Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Light & Switch Functionality #4

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

FyrbyAdditive
Copy link

Hi, this is my first time attempting to contribute someone elses project on github! Anyway, here is a summary of the changes:

  • Ability to optionally change light and switch background colour, defaults to black if unset
  • Ability to optionally add text to light and switch buttons, defaults to none if unset
  • Ability to optionally choose different light and switch icons, defaults to similar icons
  • This one I guess is subjective as you seem to have a preference for font-awesome, however I wanted to make it look more home-assistanty so the new icons are custom ones I have made based on MDI

Thank you for the work on your projects

Copy link
Owner

@jamesridgway jamesridgway left a comment

Choose a reason for hiding this comment

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

HI @timtimellis

Thanks for this! I'd really like to get this merged, but I've just realised that tests fail for me:

================================================================================== FAILURES ===================================================================================  
______________________________________________________________ TestLightToggleControl.test_initialize_sets_icon _______________________________________________________________  
                                                                                                                                                                                 
self = <tests.devdeck_home_assistant.test_light_toggle_control.TestLightToggleControl object at 0x7f4ed457f1f0>                                                                  
                                                                                                                                                                                 
    @vcr.use_cassette('tests/fixtures/test_light_toggle/test_initialize_sets_icon.yaml')                                                                                         
    def test_initialize_sets_icon(self):                                                                                                                                         
        settings = {                                                                                                                                                             
            'api_key': 'my_secret_api_key',                                                                                                                                      
            'entity_id': 'light.light1',                                                                                                                                         
            'url': 'https://homeassistant:8123',                                                                                                                                 
            'redraw_interval': 0.1                                                                                                                                               
        }                                                                                                                                                                        
        self.control = LightToggleControl(0, **settings)                                                                                                                         
        with mock_context(self.control) as ctx:                                                                                                                                  
            self.control.initialize()                                                                                                                                            
>           assert_rendered(ctx, TestingUtils.get_filename('../devdeck_home_assistant/assets/mdi/lightbulb-on.png'))                                                             
                                                                                                                                                                                 
tests/devdeck_home_assistant/test_light_toggle_control.py:23:                                                                                                                    
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
                                                                                                                                                                                 
ctx = <devdeck_core.deck_context.DeckContext object at 0x7f4ed4402f70>                                                                                                           
image_filename_or_renderer = '/home/james/projects/devdeck-home-assistant/devdeck_home_assistant/assets/mdi/lightbulb-on.png'                                                    
                                                                                                                                                                                 
    def assert_rendered(ctx, image_filename_or_renderer):                                                                                                                        
        if isinstance(image_filename_or_renderer, str):                                                                                                                          
>           assert_that(ImageChops.difference(ctx.get_image(), Image.open(image_filename_or_renderer)                                                                            
                                              .convert('RGB')).getbbox()).is_none()                                                                                              
E           TypeError: not all arguments converted during string formatting                                                                                                      
                                                                                                                                                                                 
venv/lib/python3.8/site-packages/devdeck_core/mock_deck_context.py:16: TypeError                                                                                                 
---------------------------------------------------------------------------- Captured log teardown ----------------------------------------------------------------------------  
WARNING  urllib3.connection:connection.py:547 Certificate did not match expected hostname: homeassistant. Certificate: {'subject': ((('commonName', 'homeassistant.home.jamesridg
way.co.uk'),),), 'issuer': ((('countryName', 'US'),), (('organizationName', "Let's Encrypt"),), (('commonName', 'R3'),)), 'version': 3, 'serialNumber': '04AA26D42C300E41F194F0BE
F3E200633991', 'notBefore': 'Mar 18 20:29:37 2023 GMT', 'notAfter': 'Jun 16 20:29:36 2023 GMT', 'subjectAltName': (('DNS', 'homeassistant.home.jamesridgway.co.uk'),), 'OCSP': ('
http://r3.o.lencr.org',), 'caIssuers': ('http://r3.i.lencr.org/',)}                                                                                                              
ERROR    devdeck:call_service_control.py:48 Cannot redraw key 0: HTTPSConnectionPool(host='homeassistant', port=8123): Max retries exceeded with url: /api/states/light.light1 (C
aused by SSLError(CertificateError("hostname 'homeassistant' doesn't match 'homeassistant.home.jamesridgway.co.uk'")))                                                           
____________________________________________________________ TestLightToggleControl.test_initialize_sets_icon_off _____________________________________________________________  
                                                                                                                                                                                 
self = <tests.devdeck_home_assistant.test_light_toggle_control.TestLightToggleControl object at 0x7f4ed48236d0>                                                                  
                                                                                                                                                                                 
    @vcr.use_cassette('tests/fixtures/test_light_toggle/test_initialize_sets_icon_off.yaml')                                                                                     
    def test_initialize_sets_icon_off(self):                                                                                                                                     
        settings = {                                                                                                                                                             
            'api_key': 'my_secret_api_key',                                                                                                                                      
            'entity_id': 'light.light1',                                                                                                                                         
            'url': 'https://homeassistant:8123',                                                                                                                                 
            'redraw_interval': 0.1                                                                                                                                               
        }                                                                                                                                                                        
        self.control = LightToggleControl(0, **settings)                                                                                                                         
        with mock_context(self.control) as ctx:                                                                                                                                  
            self.control.initialize()                                                                                                                                            
>           assert_rendered(ctx, TestingUtils.get_filename('../devdeck_home_assistant/assets/mdi/lightbulb-off.png'))                                                            
                                                                                                                                                                                 
tests/devdeck_home_assistant/test_light_toggle_control.py:36:                                                                                                                    
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
                                                                                                                                                                                 
ctx = <devdeck_core.deck_context.DeckContext object at 0x7f4ed44e89a0>                                                                                                           
image_filename_or_renderer = '/home/james/projects/devdeck-home-assistant/devdeck_home_assistant/assets/mdi/lightbulb-off.png'                                                   
                                                                                                                                                                                 
    def assert_rendered(ctx, image_filename_or_renderer):                                                                                                                        
        if isinstance(image_filename_or_renderer, str):                                                                                                                          
>           assert_that(ImageChops.difference(ctx.get_image(), Image.open(image_filename_or_renderer)                                                                            
                                              .convert('RGB')).getbbox()).is_none()                                                                                              
E           TypeError: not all arguments converted during string formatting                                                                                                      

Could you take a look please?

@FyrbyAdditive
Copy link
Author

Hi - great, sorry work is busy at the moment but I will look at this as soon as I can!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants