@@ -35,6 +35,7 @@ async def async_setup_platform(
3535 hass ,
3636 config [const .CONF_NAME ],
3737 config [const .CONF_TARGET ],
38+ config .get (const .CONF_FILTER_ON ) or False
3839 )
3940
4041 add_entities ([cast_device ])
@@ -45,10 +46,11 @@ class LightCastPlayer(MediaPlayerEntity):
4546 _attr_supported_features = MediaPlayerEntityFeature .PLAY_MEDIA | MediaPlayerEntityFeature .BROWSE_MEDIA
4647 _attr_device_class = MediaPlayerDeviceClass .TV
4748
48- def __init__ (self , hass : HomeAssistant , name : str , device_target : str ) -> None :
49+ def __init__ (self , hass : HomeAssistant , name : str , device_target : str , filter_on : bool ) -> None :
4950 self .hass = hass
50- self .device_target = device_target
5151 self ._attr_name = name
52+ self .device_target = device_target
53+ self .filter_on = filter_on
5254
5355 async def async_browse_media (self , media_content_type : str | None = None ,
5456 media_content_id : str | None = None ) -> BrowseMedia :
@@ -78,13 +80,12 @@ async def process_image(self, media_type: str, media_id: str) -> None:
7880 found_entities = expand_entities (self .hass , self .device_target )
7981 _LOGGER .info ('Found %d entities matching %s' , len (found_entities ), self .device_target )
8082
81- if not found_entities :
82- _LOGGER . warning ( 'No entities were matched' )
83- return
83+ valid_entities = found_entities
84+ if self . filter_on :
85+ valid_entities = [ e for e in found_entities if e . state == 'on' ]
8486
85- valid_entities = [e for e in found_entities if e .state == 'on' ]
8687 if not valid_entities :
87- _LOGGER .warning ('No targets are on ' )
88+ _LOGGER .warning ('No entities were matched ' )
8889 return
8990
9091 async with aiohttp .ClientSession () as session :
0 commit comments