@@ -1166,13 +1166,6 @@ def expand(hass: HomeAssistant, *args: Any) -> Iterable[State]:
11661166 return list (found .values ())
11671167
11681168
1169- def device_entities (hass : HomeAssistant , _device_id : str ) -> Iterable [str ]:
1170- """Get entity ids for entities tied to a device."""
1171- entity_reg = er .async_get (hass )
1172- entries = er .async_entries_for_device (entity_reg , _device_id )
1173- return [entry .entity_id for entry in entries ]
1174-
1175-
11761169def integration_entities (hass : HomeAssistant , entry_name : str ) -> Iterable [str ]:
11771170 """Get entity ids for entities tied to an integration/domain.
11781171
@@ -1214,65 +1207,6 @@ def config_entry_id(hass: HomeAssistant, entity_id: str) -> str | None:
12141207 return None
12151208
12161209
1217- def device_id (hass : HomeAssistant , entity_id_or_device_name : str ) -> str | None :
1218- """Get a device ID from an entity ID or device name."""
1219- entity_reg = er .async_get (hass )
1220- entity = entity_reg .async_get (entity_id_or_device_name )
1221- if entity is not None :
1222- return entity .device_id
1223-
1224- dev_reg = dr .async_get (hass )
1225- return next (
1226- (
1227- device_id
1228- for device_id , device in dev_reg .devices .items ()
1229- if (name := device .name_by_user or device .name )
1230- and (str (entity_id_or_device_name ) == name )
1231- ),
1232- None ,
1233- )
1234-
1235-
1236- def device_name (hass : HomeAssistant , lookup_value : str ) -> str | None :
1237- """Get the device name from an device id, or entity id."""
1238- device_reg = dr .async_get (hass )
1239- if device := device_reg .async_get (lookup_value ):
1240- return device .name_by_user or device .name
1241-
1242- ent_reg = er .async_get (hass )
1243- # Import here, not at top-level to avoid circular import
1244- from homeassistant .helpers import config_validation as cv # noqa: PLC0415
1245-
1246- try :
1247- cv .entity_id (lookup_value )
1248- except vol .Invalid :
1249- pass
1250- else :
1251- if entity := ent_reg .async_get (lookup_value ):
1252- if entity .device_id and (device := device_reg .async_get (entity .device_id )):
1253- return device .name_by_user or device .name
1254-
1255- return None
1256-
1257-
1258- def device_attr (hass : HomeAssistant , device_or_entity_id : str , attr_name : str ) -> Any :
1259- """Get the device specific attribute."""
1260- device_reg = dr .async_get (hass )
1261- if not isinstance (device_or_entity_id , str ):
1262- raise TemplateError ("Must provide a device or entity ID" )
1263- device = None
1264- if (
1265- "." in device_or_entity_id
1266- and (_device_id := device_id (hass , device_or_entity_id )) is not None
1267- ):
1268- device = device_reg .async_get (_device_id )
1269- elif "." not in device_or_entity_id :
1270- device = device_reg .async_get (device_or_entity_id )
1271- if device is None or not hasattr (device , attr_name ):
1272- return None
1273- return getattr (device , attr_name )
1274-
1275-
12761210def config_entry_attr (
12771211 hass : HomeAssistant , config_entry_id_ : str , attr_name : str
12781212) -> Any :
@@ -1291,13 +1225,6 @@ def config_entry_attr(
12911225 return getattr (config_entry , attr_name )
12921226
12931227
1294- def is_device_attr (
1295- hass : HomeAssistant , device_or_entity_id : str , attr_name : str , attr_value : Any
1296- ) -> bool :
1297- """Test if a device's attribute is a specific value."""
1298- return bool (device_attr (hass , device_or_entity_id , attr_name ) == attr_value )
1299-
1300-
13011228def issues (hass : HomeAssistant ) -> dict [tuple [str , str ], dict [str , Any ]]:
13021229 """Return all open issues."""
13031230 current_issues = ir .async_get (hass ).issues
@@ -2260,6 +2187,7 @@ def __init__(
22602187 "homeassistant.helpers.template.extensions.CollectionExtension"
22612188 )
22622189 self .add_extension ("homeassistant.helpers.template.extensions.CryptoExtension" )
2190+ self .add_extension ("homeassistant.helpers.template.extensions.DeviceExtension" )
22632191 self .add_extension ("homeassistant.helpers.template.extensions.FloorExtension" )
22642192 self .add_extension ("homeassistant.helpers.template.extensions.LabelExtension" )
22652193 self .add_extension ("homeassistant.helpers.template.extensions.MathExtension" )
@@ -2377,23 +2305,6 @@ def wrapper(_: Any, *args: _P.args, **kwargs: _P.kwargs) -> _R:
23772305 self .globals ["config_entry_id" ] = hassfunction (config_entry_id )
23782306 self .filters ["config_entry_id" ] = self .globals ["config_entry_id" ]
23792307
2380- # Device extensions
2381-
2382- self .globals ["device_name" ] = hassfunction (device_name )
2383- self .filters ["device_name" ] = self .globals ["device_name" ]
2384-
2385- self .globals ["device_attr" ] = hassfunction (device_attr )
2386- self .filters ["device_attr" ] = self .globals ["device_attr" ]
2387-
2388- self .globals ["device_entities" ] = hassfunction (device_entities )
2389- self .filters ["device_entities" ] = self .globals ["device_entities" ]
2390-
2391- self .globals ["is_device_attr" ] = hassfunction (is_device_attr )
2392- self .tests ["is_device_attr" ] = hassfunction (is_device_attr , pass_eval_context )
2393-
2394- self .globals ["device_id" ] = hassfunction (device_id )
2395- self .filters ["device_id" ] = self .globals ["device_id" ]
2396-
23972308 # Issue extensions
23982309
23992310 self .globals ["issues" ] = hassfunction (issues )
@@ -2415,12 +2326,9 @@ def warn_unsupported(*args: Any, **kwargs: Any) -> NoReturn:
24152326 "area_id" ,
24162327 "area_name" ,
24172328 "closest" ,
2418- "device_attr" ,
2419- "device_id" ,
24202329 "distance" ,
24212330 "expand" ,
24222331 "has_value" ,
2423- "is_device_attr" ,
24242332 "is_hidden_entity" ,
24252333 "is_state_attr" ,
24262334 "is_state" ,
@@ -2438,7 +2346,6 @@ def warn_unsupported(*args: Any, **kwargs: Any) -> NoReturn:
24382346 "area_id" ,
24392347 "area_name" ,
24402348 "closest" ,
2441- "device_id" ,
24422349 "expand" ,
24432350 "has_value" ,
24442351 ]
0 commit comments